2
votes

I'm trying to submit upload a photo to a website via AppleScript.

The basic experience is:

  1. Load Site [done]
  2. Click "Upload" [done - triggers Choose File prompt in what looks like the Finder, but still says Safari in top left]
  3. Type file path in prompt and submit using:

    tell application "System Events" keystroke "g" using {shift down, command down} keystroke "/Users/myUser/Pictures/myPic.jpg" key code 36 end tell

But instead the AppleScript just stops moving once the prompt appears, and waits for human interaction. How can I use AppleScript to upload an image in a prompt like this?

Demo of the web side of things: http://www.uploadify.com/demos/

Assume I can click the "Select Files" button in this demo via AppleScript. How can I continue to use AppleScript to enter the file path and submit?

1
Demo of similar web ux: uploadify.com/demos - Ryan
How are you clicking the upload button? As that code proceeds dealing with the dialog it's be worth showing. - adamh
Perhaps this is a just a matter of timing - try inserting a delay before sending the keystrokes (and perhaps also between the ⌘⇧-G command and typing the filename). Needless to say, this is not a robust solution. - mklement0

1 Answers

0
votes

You need delays in the code like @mklement0 said and to also make sure safari is activated

tell application "safari"
activate
    tell application "System Events"
        keystroke "g" using {shift down, command down}            
        delay 1.6
        keystroke "/Users/myUser/Pictures/myPic.jpg"
        delay 1.6
        key code 36
    end tell
end tell