Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos Applescript-系统事件-为“设置默认位置”;“打开文件”;弹出窗口_Macos_Applescript - Fatal编程技术网

Macos Applescript-系统事件-为“设置默认位置”;“打开文件”;弹出窗口

Macos Applescript-系统事件-为“设置默认位置”;“打开文件”;弹出窗口,macos,applescript,Macos,Applescript,Im使用系统事件来控制没有applescript库的程序。 因此,我使用系统事件来控制它 我已经让程序为它打开一个弹出窗口打开文件界面,我想让它默认到某个位置。这可能吗。 到目前为止,我已经: tell application "App Name" activate end tell tell application "System Events" tell process "App Name" tell menu bar 1 tell menu bar item "Fi

Im使用系统事件来控制没有applescript库的程序。 因此,我使用系统事件来控制它

我已经让程序为它打开一个弹出窗口打开文件界面,我想让它默认到某个位置。这可能吗。 到目前为止,我已经:

tell application "App Name"
activate
end tell
tell application "System Events"
tell process "App Name"
    tell menu bar 1
        tell menu bar item "File"
            tell menu "File"
                tell menu item "Import"
                    tell menu "Import"
                        click menu item "XML..."
                        delay 4

                    end tell
                end tell
            end tell
        end tell
    end tell
end tell
end tell
弹出窗口默认为其自己上次访问的位置。我希望它默认为给定的文件路径,如/Users/userabc/Documents/abcd.XML

谢谢

如果您有一个位置的“posix路径”并且对话框打开,您可以执行以下操作。请注意,该位置可以是文件夹或文件路径。如果它是一个文件路径,那么将选择该文件,然后只需“击键返回”即可关闭对话框并打开该文件。祝你好运

set theLocation to path to home folder
set posixLocation to POSIX path of theLocation

tell application "System Events"
    keystroke "g" using {command down, shift down}
    delay 0.5
    keystroke posixLocation
    delay 0.5
    keystroke return
end tell

这种方法唯一的问题是,当apple脚本输入文本框时,autocorrect开始填充,并将所有内容都搞糟。解决方法是从applescript复制/粘贴到。

对于插入无法使用当前输入源插入的字符,击键命令不起作用。对于一些输入源,它根本不起作用

您还可以设置文本字段的值:

tell application "System Events" to tell (process 1 where frontmost is true)
    keystroke "g" using {shift down, command down}
    tell window 1
        tell sheet 1
            set value of text field 1 to "/usr/share/dict/connectives"
            click button 1
        end tell
        click button "Open"
    end tell
end tell

好极了,真是太棒了!我还可以提示输入默认文件名和文件路径吗?