Applescript 保存文件菜单:如何将目标指向桌面?
Applescript save file menu: how to point destination to Desktop?
我有一个 applescript 可以触发 Microsoft Outlook 的导出事件。除了关于保存导出的 .olm 文件的弹出菜单外,它可以很好地处理所有对话框。
我试图让它可靠地转到桌面,但它转到了 Outlook 中上次使用(保存)的任何文件夹。我认为菜单忽略了我设置不同目的地的尝试。
如何调试并正确执行?相关行:
set theExportToFolder to "~/Desktop"
tell text field 2 of sheet 1 of window "Export to Archive File (.olm)"
set value to theExportToFolder
end tell
tell sheet 1 of window "Export to Archive File (.olm)"
click button "Save"
delay 0.5
end tell
假设您的对话框是标准的 'save as...',您可以使用 command/shift/d 键强制转到桌面,这可以使用 :
keystroke "d" using {command down, shift down}
这是通过 GUI 脚本(键盘模拟)完成的另存为的完整示例。在这种情况下,它是为 TextEdit 完成的(实际上 textEdit 有一个另存为 Applescript 命令!)。您需要对 Outlook 导出对话框遵循相同的逻辑。
tell application "TextEdit" to activate
tell application "System Events"
keystroke "s" using {command down} -- save command from menu
keystroke "my_title" -- fill title of the document in save window
keystroke "g" using {command down, shift down} -- open goto dialog
keystroke "/Users/imac27/Desktop/mySamples" -- path from Documents folder
keystroke return -- close go to dialog with enter key
keystroke return -- close the save as dialog with enter key
end tell
您的文件夹路径必须根据您的用户和文件夹进行调整。在此示例中,文档保存在桌面上的文件夹 mySamples 中。
当然,如果您要保存的文件夹是桌面、文档等标准文件夹...只需使用快捷键直接转到该文件夹:您不需要转到功能。
我有一个 applescript 可以触发 Microsoft Outlook 的导出事件。除了关于保存导出的 .olm 文件的弹出菜单外,它可以很好地处理所有对话框。
我试图让它可靠地转到桌面,但它转到了 Outlook 中上次使用(保存)的任何文件夹。我认为菜单忽略了我设置不同目的地的尝试。
如何调试并正确执行?相关行:
set theExportToFolder to "~/Desktop"
tell text field 2 of sheet 1 of window "Export to Archive File (.olm)"
set value to theExportToFolder
end tell
tell sheet 1 of window "Export to Archive File (.olm)"
click button "Save"
delay 0.5
end tell
假设您的对话框是标准的 'save as...',您可以使用 command/shift/d 键强制转到桌面,这可以使用 :
keystroke "d" using {command down, shift down}
这是通过 GUI 脚本(键盘模拟)完成的另存为的完整示例。在这种情况下,它是为 TextEdit 完成的(实际上 textEdit 有一个另存为 Applescript 命令!)。您需要对 Outlook 导出对话框遵循相同的逻辑。
tell application "TextEdit" to activate
tell application "System Events"
keystroke "s" using {command down} -- save command from menu
keystroke "my_title" -- fill title of the document in save window
keystroke "g" using {command down, shift down} -- open goto dialog
keystroke "/Users/imac27/Desktop/mySamples" -- path from Documents folder
keystroke return -- close go to dialog with enter key
keystroke return -- close the save as dialog with enter key
end tell
您的文件夹路径必须根据您的用户和文件夹进行调整。在此示例中,文档保存在桌面上的文件夹 mySamples 中。
当然,如果您要保存的文件夹是桌面、文档等标准文件夹...只需使用快捷键直接转到该文件夹:您不需要转到功能。