使用AppleScript更改當前工作目錄(cwd)最簡單的方法是什麼?這將等同於操作系統的cd
或Python的os.chdir
。如果一個目標目錄不存在,會很快創建(但這是非常可選的)。如何使用AppleScript更改當前工作目錄
1
A
回答
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
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 page和this related question(或this one)。
+0
感謝您的建議!我正在使用AppleScript來啓動(運行/啓動)第三方應用程序(如Chrome或Firefox)。我必須使用AppleScript是有原因的。當應用程序啓動時,它將其「主目錄」設置爲其默認應用程序文件夾,如「/ Applications/Firefox.app/Contents」。因此,任何文件打開,文件保存都會在默認應用程序文件夾中打開。我想通過在應用程序啓動之前將當前工作目錄更改爲所選目錄來覆蓋此內容。我害怕'告訴應用程序「Finder」'不能用於這種情況。其他建議? – alphanumeric
相關問題
- 1. 如何更改當前工作目錄
- 2. 無法更改當前工作目錄
- 3. SWI Prolog更改工作目錄/獲取當前工作目錄?
- 4. 使用Nodejs更改bash終端的當前工作目錄
- 5. 我該如何讓vim自動更改當前工作目錄?
- 6. 將工作目錄更改爲當前腳本的目錄
- 7. SQL Plus:如何更改目錄並顯示當前工作目錄
- 8. 如何更改當前工作目錄並使用paramiko設置環境變量?
- 9. 如何使用批處理文件更改當前工作目錄
- 10. 如何更改SBCL的當前目錄?
- 11. 在Python中更改調用者的當前工作目錄
- 12. 更改當前目錄
- 13. 如何獲得當前工作目錄
- 14. 如何設置當前工作目錄?
- 15. SHAutoComplete&當前工作目錄?
- 16. vimrc - 當前工作目錄
- 17. Sublime Text:如何查看當前工作目錄以及如何更改
- 18. 如何使os.walk改變當前目錄
- 19. 獲取當前工作空間目錄的更改列表號
- 20. 以編程方式更改進程的當前工作目錄
- 21. 將工作目錄更改爲當前打開的文件
- 22. VIM:僅更改當前緩衝區的工作目錄
- 23. 只比較當前工作目錄中的更改
- 24. 使用.htaccess更改工作目錄
- 25. 如何使用python 3獲取當前工作目錄?
- 26. 如何將當前工作目錄更改爲特定目錄並在特定目錄下執行程序?
- 27. 在命令提示符下使用python更改當前工作目錄
- 28. 如何在當前工作目錄中創建一個目錄,使用Java
- 29. 如何更改我的tcsh提示以顯示我當前的工作目錄?
- 30. 如何在不更改當前工作目錄的情況下添加文件?
[**執行的AppleScript腳本,Shell命令**](https://developer.apple.com/library/mac /documentation/applescript/conceptual/applescriptx/concepts/work_with_as.html#//apple_ref/doc/uid/TP40001568-1148121) –