Applescript在相对路径上运行

时间:2015-05-08 11:17:02

标签: path applescript latex

我正在运行一个非常愚蠢的应用程序,以清理我的乳胶输出文件。 我想将该应用程序放在我拥有的每个乳胶项目中,并能够运行该应用程序。应用程序应根据其放置位置检测其位置: 例如:/Users/User/Documents/LatexProject1/clean.app来清除.../LatexProject1文件夹。

到目前为止,我设法运行基于绝对路径的脚本,这非常烦人,每次运行新的Latex项目时都必须更改应用程序的路径。

你能帮我编辑我的代码吗?

set subfolderOfSharedFolder to quoted form of "Users/lukas/Google Drive/006 semester/00_Bachelorarbeit/00_Documentation"

set response to display dialog "Trash all of the output files in your latex folder?" buttons {"Yes, I'm ready", "No"} default button 2 cancel button 2 with title "<subfolder name> Folder Prep" with icon caution

if button returned of response is "Yes, I'm ready" then
    -- run spotlight search
    set filesToDelete to paragraphs of (do shell script "mdfind 'kMDItemFSName == *.lot c' -onlyin " & subfolderOfSharedFolder)

    -- convert posix paths to file specifiers
    repeat with thisFile in filesToDelete
        set (contents of thisFile) to POSIX file thisFile
    end repeat

    tell application "Finder"
        delete filesToDelete
    end tell


    -- run spotlight search 2
    set filesToDelete to paragraphs of (do shell script "mdfind 'kMDItemFSName == *.out c' -onlyin " & subfolderOfSharedFolder)

    -- convert posix paths to file specifiers
    repeat with thisFile in filesToDelete
        set (contents of thisFile) to POSIX file thisFile
    end repeat

    tell application "Finder"
        delete filesToDelete
    end tell

    -- run spotlight search 2
    set filesToDelete to paragraphs of (do shell script "mdfind 'kMDItemFSName == *.aux c' -onlyin " & subfolderOfSharedFolder)

    -- convert posix paths to file specifiers
    repeat with thisFile in filesToDelete
        set (contents of thisFile) to POSIX file thisFile
    end repeat

    tell application "Finder"
        delete filesToDelete
    end tell

    -- run spotlight search 2
    set filesToDelete to paragraphs of (do shell script "mdfind 'kMDItemFSName == *.blg c' -onlyin " & subfolderOfSharedFolder)

    -- convert posix paths to file specifiers
    repeat with thisFile in filesToDelete
        set (contents of thisFile) to POSIX file thisFile
    end repeat

    tell application "Finder"
        delete filesToDelete
    end tell

    -- run spotlight search 2
    set filesToDelete to paragraphs of (do shell script "mdfind 'kMDItemFSName == *.bbl c' -onlyin " & subfolderOfSharedFolder)

    -- convert posix paths to file specifiers
    repeat with thisFile in filesToDelete
        set (contents of thisFile) to POSIX file thisFile
    end repeat

    tell application "Finder"
        delete filesToDelete
    end tell


    -- run spotlight search 2
    set filesToDelete to paragraphs of (do shell script "mdfind 'kMDItemFSName == *.glg c' -onlyin " & subfolderOfSharedFolder)

    -- convert posix paths to file specifiers
    repeat with thisFile in filesToDelete
        set (contents of thisFile) to POSIX file thisFile
    end repeat

    tell application "Finder"
        delete filesToDelete
    end tell


    -- run spotlight search 2
    set filesToDelete to paragraphs of (do shell script "mdfind 'kMDItemFSName == *.glo c' -onlyin " & subfolderOfSharedFolder)

    -- convert posix paths to file specifiers
    repeat with thisFile in filesToDelete
        set (contents of thisFile) to POSIX file thisFile
    end repeat

    tell application "Finder"
        delete filesToDelete
    end tell


    -- run spotlight search 2
    set filesToDelete to paragraphs of (do shell script "mdfind 'kMDItemFSName == *.gls c' -onlyin " & subfolderOfSharedFolder)

    -- convert posix paths to file specifiers
    repeat with thisFile in filesToDelete
        set (contents of thisFile) to POSIX file thisFile
    end repeat

    tell application "Finder"
        delete filesToDelete
    end tell


    -- run spotlight search 2
    set filesToDelete to paragraphs of (do shell script "mdfind 'kMDItemFSName == *.idx c' -onlyin " & subfolderOfSharedFolder)

    -- convert posix paths to file specifiers
    repeat with thisFile in filesToDelete
        set (contents of thisFile) to POSIX file thisFile
    end repeat

    tell application "Finder"
        delete filesToDelete
    end tell


    -- run spotlight search 2
    set filesToDelete to paragraphs of (do shell script "mdfind 'kMDItemFSName == *.ist c' -onlyin " & subfolderOfSharedFolder)

    -- convert posix paths to file specifiers
    repeat with thisFile in filesToDelete
        set (contents of thisFile) to POSIX file thisFile
    end repeat

    tell application "Finder"
        delete filesToDelete
    end tell


    -- run spotlight search 2
    set filesToDelete to paragraphs of (do shell script "mdfind 'kMDItemFSName == *.lof c' -onlyin " & subfolderOfSharedFolder)

    -- convert posix paths to file specifiers
    repeat with thisFile in filesToDelete
        set (contents of thisFile) to POSIX file thisFile
    end repeat

    tell application "Finder"
        delete filesToDelete
    end tell


    -- run spotlight search 2
    set filesToDelete to paragraphs of (do shell script "mdfind 'kMDItemFSName == *.log c' -onlyin " & subfolderOfSharedFolder)

    -- convert posix paths to file specifiers
    repeat with thisFile in filesToDelete
        set (contents of thisFile) to POSIX file thisFile
    end repeat

    tell application "Finder"
        delete filesToDelete
    end tell


    -- run spotlight search 2
    set filesToDelete to paragraphs of (do shell script "mdfind 'kMDItemFSName == *.gz c' -onlyin " & subfolderOfSharedFolder)

    -- convert posix paths to file specifiers
    repeat with thisFile in filesToDelete
        set (contents of thisFile) to POSIX file thisFile
    end repeat

    tell application "Finder"
        delete filesToDelete
    end tell


    -- run spotlight search 2
    set filesToDelete to paragraphs of (do shell script "mdfind 'kMDItemFSName == *.toc c' -onlyin " & subfolderOfSharedFolder)

    -- convert posix paths to file specifiers
    repeat with thisFile in filesToDelete
        set (contents of thisFile) to POSIX file thisFile
    end repeat

    tell application "Finder"
        delete filesToDelete
    end tell

    if button returned of (display dialog "The APP files have been trashed." buttons {"OK"} default button 1 with title "SuchAndSuch Folder Prep" with icon 1) is "OK" then
    end if
end if

1 个答案:

答案 0 :(得分:0)

Path to me”给出了脚本本身的路径。由于您需要封闭文件夹,因此您可以使用类似

的内容
tell application "Finder"
    return folder of (path to me)
end tell 

编辑添加:您将转换此行

set subfolderOfSharedFolder to quoted form of "Users/lukas/Google Drive/006 semester/00_Bachelorarbeit/00_Documentation" 

这样的事情:

tell application "Finder"
    set subfolderOfSharedFolder to POSIX path of (folder of (path to me) as text)
end tell

假设您将要运行的脚本放在文件夹"Users/lukas/Google Drive/006 semester/00_Bachelorarbeit/00_Documentation"

相关问题