Re: Passing dropped items to shell script
Re: Passing dropped items to shell script
- Subject: Re: Passing dropped items to shell script
- From: "Mark J. Reed" <email@hidden>
- Date: Fri, 15 May 2009 07:45:58 -0400
On Fri, May 15, 2009 at 1:34 AM, Marconi <
email@hidden> wrote:
> I was using display dialog to show thepath and it looked right.
You were doing
dialog dialog thepath
but that's different from
display dialog "\"thepath\""
which will just show you a dialog containing "thepath". Inside a double-quoted string, names are just names. They aren't expanded like in Perl. Perl uses sigils in variable names ($, @) partially so they can be recognized inside strings; Applescript has no such mechanism, and it would be terribly inefficient and chaotic to have it look for every word in a string to see if it's a variable and expand it if it is!
> FYI, this is what I have now. I added the script to the application bundle
> and call it there:
>
> on open dropped_items
> repeat with i from 1 to the count of dropped_items
> set this_item to (item i of dropped_items)
> set thepath to POSIX path of this_item
> set objectFolder to (path to me) as string
> do shell script (POSIX path of objectFolder) &
> "Contents/Resources/perlscript.pl " & quoted form of thepath
> end repeat
> end open
As Shane said, that only works if the application is not in a folder whose POSIX path name contains spaces. Also, you're doing a lot of stuff every time through the loop that only needs to be done once - not even once per "open", but just once period - and using a counting loop where a foreach loop would work:
property perlScript: quoted form of (POSIX path of (path to me) & "Contents/Resources/perlscript.pl")
on open dropped_items
repeat with this_item in dropped_items
do shell script perlScript & " " & quoted form of POSIX path of this_item
end repeat
end open
as Skeeve suggested, you could also construct the Perl script to take a list of items instead of a single one,
e.g. by wrapping the main body of the Perl code in a while (@ARGV) { ... your code here...; shift @ARGV; }. In that case, you would want to do something like this:
on open dropped_items
set commandLine to perlScript
repeat with this_item in dropped_items
set commandLine to commandLine & " " & quoted form of POSIX path of this_item
end repeat
do shell script commandLine
end open
--
Mark J. Reed <
email@hidden>
_______________________________________________
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