Re: Run script with arguments
Re: Run script with arguments
- Subject: Re: Run script with arguments
- From: Nicola Vitacolonna <email@hidden>
- Date: Mon, 29 Dec 2014 23:20:44 +0100
On 29 Dec 2014, at 22:35, Deivy Petrescu <email@hidden> wrote:
>
>
>> On Dec 29, 2014, at 11:16 , Nicola Vitacolonna <email@hidden> wrote:
>>
>> Hi,
>> I have run this script with AppleScript 2.4 (OS X Yosemite):
>>
>> #!/usr/bin/env osascript
>> script Foo
>> on run argv
>> repeat with i from 1 to (count argv)
>> log item i of argv
>> end repeat
>> return 42
>> end run
>> end script
>>
>> run Foo
>> -- Results:
>> -- runs fine in Script Editor
>> -- execution error: «script Foo» doesn’t understand the “count” message. (-1708) in osascript
>> -- Remarks:
>> -- Cannot pass arguments to Foo
>>
>> run script Foo
>> -- As above; besides, it does not log anything (apart from the return value)
>>
>> run script Foo with parameters {"a", 1}
>> -- Results:
>> -- runs in both Script Editor and osascript, but does not output/log anything (apart from the return value)
>> -- Remarks:
>> -- Not officially documented? (The AS Language Guide says run script needs text or file reference)
>>
>> The comments pretty much say it all, and raise two questions:
>>
>> 1) Is this behaviour a bug (I think so)?
>> 2) Is there a (possibly officially supported) way to run a script with arguments from another script *and* having it log? This is the workaround I’m using:
>>
>> script Foo
>> property argv : {}
>>
>> on exec:(argv as list)
>> set my argv to argv
>> run me
>> end exec:
>>
>> on run
>> repeat with i from 1 to (count my argv)
>> log item i of argv
>> end repeat
>> end run
>> end script
>>
>> Foo's exec:{"a", 1}
>>
>> Nicola
>>
>
> By the way, it is not logging but it sees and receives the arguments!
>
>
> <script>
> script Foo
> on run argv
> repeat with i from 1 to (count argv)
> --say "hi"
> say item i of argv
> end repeat
> return 42
> end run
> end script
>
>
> run script Foo with parameters {"a", 1}
> </script>
>
> I believe I’ve noticed before but can’t remember if I have noticed recently, that scripts fail to log items in handlers (in the main script).
> Have to check!
> It does log on handles in the main script.
I believe this has started with Yosemite. At least, in Lion logging is working. It seems as if run script forked a thread or a process but forgets to set its stdout. Btw, you can get rid of the error in osascript by replacing `count my argv` with `my argv’s length`.
Nicola
_______________________________________________
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