我写了一个小文章,在safari中附加文件。如果我手动附加它们,一切都会完全发生,但由于某些未知原因,即使正在选择并正确提交附件,附件也不会上传。
我花了几个小时对此进行排查并尝试不同的变化而没有成功。
这是附加它们的代码。除了模拟鼠标点击的AppleScript之外,我正在使用cliclick。
set posix to "/Users/ea/Desktop/Guru/Deliverables" --set folder path
tell application "System Events"
keystroke "g" using {shift down, command down}
keystroke posix
delay 1
keystroke return
delay 2
keystroke "a" using {command down}
delay 5
do shell script "/usr/local/bin/cliclick m:381,339"
delay 3
do shell script "/usr/local/bin/cliclick m:818,590"
delay 2
do shell script "/usr/local/bin/cliclick tc:."
delay 2
end tell
选择的文件就像他们应该的那样
单击选择后,不会上传任何内容。
答案 0 :(得分:0)
试试这个
tell application "Google Chrome" --Whatever your using
activate
set posix to "/Users/ea/Desktop/Guru/Deliverables/private" --are the files in here
tell application "System Events"
keystroke "g" using {shift down, command down}
keystroke posix
delay 1
keystroke return
delay 2
keystroke "a" using {command down}
delay 5
key code 36
end tell
end tell
答案 1 :(得分:0)
出于好奇,你有没有得到它的工作?你在safari中附加文件是什么意思?选择"文件选择窗口后选择文件"打开?
我知道这已经很晚了,有人似乎已经回答了你的问题,但是你没有回应说是否有效,所以我创造了类似的东西,可能有所帮助:
to clickClassName(theClassName, elementnum)
tell application "Safari"
do JavaScript "document.getElementsByClassName('" & theClassName & "')[" & elementnum & "].click();" in document 1
end tell
end clickClassName
to getValueFromClass(theclass, num)
tell application "Safari"
tell document 1
set theFirstTableHTML to do JavaScript "\n document.getElementsByClassName('" & theclass & "')[" & num & "].value"
return theFirstTableHTML
end tell
end tell
end getValueFromClass
on run
choose file with prompt "Which folder would like average file size calculated?"
open {result}
end run
on open theimage
--tell application "Finder" to set xx to every file in item 1 of theimage
--display dialog "Hey! the file's alias is: " & (path of theimage as string)
--display dialog theimage
set filepath to POSIX path of theimage
tell application "Safari" to open location "https://upload.vstanced.com"
delay 2
clickClassName("btn btn-big white outline", 0)
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
delay 1
clickClassName("btn btn-big green", 0)
set thedirectlink to ""
repeat 15 times
set thedirectlink to getValueFromClass("r2", 1)
delay 1
if thedirectlink is not equal to "" then
exit repeat
end if
end repeat
set the clipboard to thedirectlink
tell application "Safari" to close current tab of window 1
display notification "Upload complete" with title "VStanced Upload" subtitle thedirectlink sound name "blow"
end open
这是一个Droplet(在脚本编辑器中保存为"文件格式" as" application"),当您将图像拖到其上时,它会打开一个图像托管站点,使用javascript打开"文件选择窗口",然后几乎完全做你的工作。
选择并输入文件后,它还会选择"直接链接"从一个小小的"切换按钮" thingy,将直接链接复制到剪贴板,关闭选项卡,播放声音并显示通知。如果你最终尝试它并且它不起作用,延长延迟。它做了一切(我99%肯定)。但是如果safari尚未打开,它可能需要很长时间才能到达页面,这将使一切变得混乱。我也将尝试添加等待"等待"用于加载页面。