Question

I wrote a little applescript that attaches files in safari. Everything happens exactly how it would if I were attaching them manually, but for some unknown reason the attachments are not uploading even though they are being selected and submitted correctly.

I've spent a couple hours troubleshooting this and trying different variations with no success.

Here is the code that attaches them. I'm using cliclick in addition to applescript, which emulates mouse clicks.

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

files selected like they're supposed to enter image description here

Upon clicking choose, nothing uploads. enter image description here

Was it helpful?

Solution

Try This

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

OTHER TIPS

Out of curiosity did you ever get it to work? and what do you mean by attaches files in safari? its select the files after you have the "file choosing window" open?

i know this is late, and someone seems to have already answered your question, but yeah you didn't respond to say if it worked or not, so heres something similar i created that might help:

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

This is a droplet (in script editor save it with "file format" as "application"), when you drag an image onto it, it opens up an image hosting site, uses javascript to open the "file choosing window", and then pretty much does exactly what yours does.

After it selects and enters the file, it also selects "direct link" from a little "toggle button" thingy, copies the direct link to the clipboard, closes the tab, plays sound and shows a notification. if you end up trying it and it doesnt work, lengthen the delays. it does everything (i'm 99% sure). But if safari's not already open it will probably take too long to get to the page and that will mess everything up. Im also going to try to add parts that "wait" for the page to load.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top