如何使用AppleScript更改当前工作目录

时间:2014-05-20 05:48:19

标签: applescript chdir

使用AppleScript更改当前工作目录(cwd)的最简单方法是什么。它等同于操作系统的cd或Python的os.chdir。如果目标目录不存在将会在飞行中创建(但这将是高度可选的)将是很好的。

2 个答案:

答案 0 :(得分:1)

您可能正在考虑做这样的事情:

tell application "Finder"
# ^^^ or whatever application you want to control up there
    # to get to a file...
    set filePath to POSIX file "/Users/username/Documents/new.mp3"

    # to get to a folder...
    set testFolder to POSIX path "/Users/username/test"
    if (exists (folder testFolder)) then
        say "folder exists"
    else
        make new folder at testFolder
    endif
end tell

我的答案取决于答案on this pagethis related question(或this one)。

答案 1 :(得分:1)

如果您希望使用应用程序保存对话框...

set filePath to "path/to/my/file"

tell application "System Events"
    -- Once save dialog is open
    keystroke "g" using {shift down, command down}
    delay 1
    set value of text field 1 of sheet 1 of sheet 1 of window 1 to filePath
end tell