Does anyone know how to pass a variable from automator to Applescript?

I already have an automator application that works perfectly well on a single file. I drag a file onto it and it does exactly what it is supposed to do. Now I want to drag a list of files onto the app and have it repeat the same function for each file. I figure I am going to have to to the looping in Applescript within Automator, but I'd love to start by knowing how I can simply pass a variable I created in Automator to the Execute Applescript task. Anyone out there know how to do that? Should be easy, right?

Posted on Jan 29, 2022 12:36 PM

Reply
5 replies

Jan 29, 2022 7:19 PM in response to Mattmerk

You are providing rsync with an HFS path and not a POSIX path, so it just goes berserk.


on run {input, parameters}

	repeat with afile in input
		set unix_path to (POSIX path of afile) as text
		# do shell script "echo " & unix_path & " >> ~/Desktop/logme.txt"
		do shell script "rsync -R " & unix_path & space & "/Volumes/RAID_1/_Shows/_Staging"
	end repeat
	return input

end run



Of course, if you are just doing shell stuff and have no specific AppleScript coding requirement, you could use a Run Shell Script action instead:


Jan 29, 2022 5:24 PM in response to VikingOSX

Thank you! This is super helpful and you have my deep, deep appreciation. I can write a list of files to that logme text file, but this line causes rsync issues. Any clues on that, maybe? I'm placing it just below your comment line: -- what ever tasks you want performed on each file in the input list


Here's the line that causes the issue:

do shell script "rsync -R " & (afile as text)'s quoted form & "/Volumes/RAID_1/_Shows/_Staging"


Jan 30, 2022 4:31 AM in response to Mattmerk

You are welcome.


On macOS Catalina and later, the default shell is now zsh which Apple plans to continue supporting due to its MIT license. The near prehistoric Bash 3.2.57 shell remains available for those that prefer it, though unsupported by Apple. Newer versions (e.g. v5) of the Bash shell (and syntax examples that you will likely see in Google searches) are not installed by Apple due to its GNU licensing (GPL) v3 restrictions that Apple does not agree too.


You can find more information on the use of the zsh shell here.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Does anyone know how to pass a variable from automator to Applescript?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.