0

第一次使用applescripting,我已经编写了一个脚本,该脚本创建一个.nfo 文件,其中包含基于文件夹名称的电影的IMDB链接。

目前,该脚本已设置为向用户询问包含所有电影的文件夹,并在该文件夹中循环,直到处理完所有子文件夹。

结构是:

  • 电影
    • 电影 1
      • 视频文件
      • 电影1.信息
    • 电影 2
      • 视频文件
      • 电影2.信息
    • 电影 3
      • 视频文件
      • 电影3.信息

等等...

我需要帮助添加一个 if-then-else 语句,该语句首先检查 nfo 文件是否已经存在,如果存在,只需增加计数器以移动到下一个文件夹或运行我当前的脚本代码。

我尝试过类似的东西

if (theFiles contains files whose name extension is nfo) then
    i = i + 1
else
    -- My Code
end if

它似乎并不关心,只是再次处理所有文件夹,用新的 nfo 替换当前的 nfo。

当前的 AppleScript:

property imdburl : ""
property newurl : ""
property FolderPath1 : ""
property FolderPath : ""
property Foldername : ""

tell application "Finder"
    activate
    set theFolder to choose folder with prompt "Select the Movie Folder."
    set theList to every folder of theFolder
    repeat with i from 1 to count the theList
        set thisItem to item i of theList as alias
        set currentName to name of thisItem
        --set currentfolder to get the POSIX path of thisItem
        set theFiles to every file of folder thisItem as alias list

        if (theFiles contains files whose name extension is nfo) then
            i = i + 1
        else
            tell application "Finder"
                set FolderPath1 to thisItem -- sets file path to folder you select
                set ParentFolder to container of FolderPath1 -- sets the parent folder of the folder you select
                set Foldername to name of folder FolderPath1 -- sets the folder name as text
                set FolderPath to get the POSIX path of FolderPath1
                set newurl to "http://google.com/search?q=" & Foldername & "+imdb&btnI=I%27m+Feeling+Lucky"
                --set the clipboard to newurl -- sets foldername to the clipboard
            end tell

            tell application "Safari"
                open location newurl
                activate
                delay 3
                set imdburl to URL of current tab of window 1
                set the clipboard to FolderPath
                close window 1
            end tell

            tell application "TextEdit"
                activate
                make new document
                set text of document 1 to imdburl
                set Foldername to text 1 thru -(7 + 1) of Foldername
                save document 1 in FolderPath & "/" & Foldername
                close document 1
            end tell

            tell application "Finder" to set name extension of (files of FolderPath1 whose name extension is "rtf") to "nfo"
        end if
    end repeat
end tell
4

1 回答 1

0

此示例显示如何检查文件夹中的应用程序包(只是为了便于测试)。将 .app 替换为 .ifo 即可获得所需的内容。

on foo()
    tell application "Finder"
        set someFolder to choose folder
        set aList to name of files of someFolder as list
        set AppleScript's text item delimiters to return
        return ".app" is in (aList & return as text)
    end tell
end foo

on run {}
    foo()
end run

请注意,与通常所说的相反,重复循环不是获取文件夹文件列表的必要条件。

于 2013-04-18T23:10:40.810 回答