• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Pass Finder Selection to Shell Argument
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pass Finder Selection to Shell Argument


  • Subject: Re: Pass Finder Selection to Shell Argument
  • From: Christopher Nebel <email@hidden>
  • Date: Fri, 7 Sep 2007 20:47:32 -0700

On Sep 6, 2007, at 2:17 PM, David Wolfe wrote:

This is what I thought I should be able to do. But I couldn't figure out how to get the Finder selection from the workflow to pass to the shell script except to wrap it in an Applescript with a variable.

Like I said, the Finder itself will pass the target files to the workflow, and they'll show up as input to the first action. (In the case of Run Shell Script, they'll be a set of POSIX paths, one per line.) There's no need to manually get the Finder selection -- though that can be useful for testing; use the Get Selected Finder Items action -- and it's actually wrong to do so, because you can control- click on something that's not selected.


I'm assuming where you wrote, "pass input as parameters," you meant to say "argument?" The options are Standard Input or Argument.

Er, yes, "as arguments." My mistake.

Can you explain the script you posted so I can learn how to do things like in the future? For example, what does the first line do? What does the "$f" mean in the third line? Does "done" make the shell session quit?

That's just what a loop looks like in sh. It's the notional equivalent of "repeat with f in parameters ... end repeat". Variable references in sh always start with a "$", so "$f" is simply the current item in the loop.


If you haven't filled in a script of your own, the Run Shell Script action will supply a do-nothing script for the selected shell and input settings that simply echoes the original input as the output. Flip through the various shells to see what they all look like.


--Chris Nebel AppleScript Engineering

On Sep 6, 2007, at 4:49 PM, Christopher Nebel wrote:

On Sep 5, 2007, at 2:22 PM, David Wolfe wrote:

I know this may inflame the Applescript/Shell script debate again, but I'm trying to automate something that apparently can only be done at a command prompt. Please prove this wrong and show me an Applescript way.

I'm trying to use Automator to create a Finder plug-in that will allow a right-click on selected file(s) to add those files to the Dock. So far, I've been able to get the Finder plug-in to work, calling an Applescript in which I'm using "do shell script" to add the item(s) to the Dock. But I can't get the selected file to pass to the Shell Script as an argument. Here is the Workflow:

Get Specified Finder Items > Run Applescript

	on run {input, parameters}
		do shell script "additemtodock "
		return
	end run

If you're using Automator to create a Finder plug-in, then there are two things to be aware of. First, the clicked items will be passed to the workflow -- there's no need, and it's actually incorrect, to get the Finder selection in the workflow itself. Second, if all your Run AppleScript action does is call "do shell script", why not use a Run Shell Script action instead? Your entire workflow would look like this:


	Run Shell Script (/bin/sh, pass input as parameters)

		for f in "$@"
		do
			additemtodock "$f"
		done


--Chris Nebel AppleScript Engineering




_______________________________________________ Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >Pass Finder Selection to Shell Argument (From: David Wolfe <email@hidden>)
 >Re: Pass Finder Selection to Shell Argument (From: Christopher Nebel <email@hidden>)
 >Re: Pass Finder Selection to Shell Argument (From: David Wolfe <email@hidden>)

  • Prev by Date: Re: plist Files
  • Next by Date: Re: plist Files
  • Previous by thread: Re: Pass Finder Selection to Shell Argument
  • Next by thread: List network neighbourhood ?
  • Index(es):
    • Date
    • Thread