0

I'm making a automator service to select a file, then upload the selected file using a shell script. I can't seem to get my variables to work. I'm VERY new to Automator and AppleScript and don't really know much about them, so they might just be newbie mistakes.

If there is a better way to do this, please let me know!

Here's my AppleScript code:

on run {input01, input02, path}
    set input01 to "scp -i /Users/jeffArries/Desktop/jeffarries.pem -rp /Users/jeffArries/Desktop/Website_Testing_Folder/"
    set input02 to "[email protected]:/var/www/html"
    do shell script "{input01} & {Path} & {input02}"
end run

And a screenshot of automator:enter image description here

0

1 Answer 1

3

You don't need to do it your way. When creating an Automator Service the paths of the selected items are given to the service automatically. All you need to do is to select "Files & Folders" in the Menu at the top (in your screenshot you selected "no input").

After that you don't need to use Automator variables, all paths can be found as a list inside the input parameter.

After that you should build your shell command like an ordinary string and execute it via do shell script.

Try this to get started, I filled it up with helpful comments for you:

on run {input, parameters}

    -- setting your AppleScript variables
    set input01 to "scp -i /Users/jeffArries/Desktop/jeffarries.pem -rp /Users/jeffArries/Desktop/Website_Testing_Folder/"
    set input02 to "[email protected]:/var/www/html"

    -- loop through selected finder items
    repeat with aFinderItem in input
        -- check if the aFinderItem is a file and not anything else
        tell application "System Events" to set theItemIsAFile to ((get class of item (aFinderItem as text)) = file)
        if theItemIsAFile then
            -- store the POSIX path of the file
            set theItemsPosixPath to POSIX path of aFinderItem
            -- build the shell scp command
            set myShellCommand to input01 & " " & quoted form of theItemsPosixPath & " " & input02
            -- exceute the command
            do shell script myShellCommand
        end if
    end repeat
    return input
end run

Enjoy, Michael / Hamburg

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.