使用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) –