Applescript在相对路径上运行

问题描述 投票:0回答:1

我正在运行一个非常愚蠢的应用程序,以清理我的乳胶输出文件。 我想将该应用程序放置在我拥有的每个乳胶项目中,并能够运行该应用程序。 该应用程序应根据其放置位置来检测其位置:例如: /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
path applescript latex
1个回答
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"文件夹中

© www.soinside.com 2019 - 2024. All rights reserved.