我想在Chrome中使用AppleScript上传文件。文件路径包含一个点(。),但此脚本无法将点发送到“转到文件夹:”。
on run argv
tell application "System Events"
tell application "Google Chrome" to activate
delay 2
log argv
keystroke "g" using {command down, shift down}
delay 1
keystroke item 1 of argv
end tell
end run
我正在使用此命令运行脚本:
nsadmins-Mac:util nsadmin$ osascript macUploadChrome.scpt "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py"
运行此脚本后,此文本显示在“转到文件夹”字段中:
/System/Library/Frameworks/Pythonframework/Versions//lib/python/socketpy
答案 0 :(得分:1)
这很奇怪,但如果您尝试使用复制/粘贴,该怎么办:
set the clipboard to (item 1 of argv as string)
keystroke "g" using {command down, shift down}
delay 1
keystroke "v" using {command down}
答案 1 :(得分:0)
为何选择Chrome?老实说好奇,我从来没有遇到任何Safari问题。反正,
--set filepath to POSIX path of theimage
--^^set filepath to the desired file path^^
delay 2
tell application "System Events"
activate application "Safari"
delay 0.5
keystroke "g" using {shift down, command down} --open goto
set the clipboard to filepath
keystroke "v" using {command down}
delay 0.7
keystroke return -- enter goto text
delay 0.4
keystroke return --press enter on file
end tell
也许该文件路径太长了。我怀疑它。尝试使用此功能,如果它不能与Chrome一起使用,请尝试使用Safari,看看是否存在问题。这是为了在"文件选择窗口"已经打开,但我写的完整脚本有点广泛,如果你想看到它,请告诉我。