• 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: Run script with arguments
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Run script with arguments


  • Subject: Re: Run script with arguments
  • From: Deivy Petrescu <email@hidden>
  • Date: Mon, 29 Dec 2014 16:35:43 -0500

> 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.





Deivy Petrescu
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


  • Follow-Ups:
    • Re: Run script with arguments
      • From: Nicola Vitacolonna <email@hidden>
References: 
 >Run script with arguments (From: Nicola Vitacolonna <email@hidden>)

  • Prev by Date: AUTO: Allyn Martin is out of office.
  • Next by Date: Re: Run script with arguments
  • Previous by thread: Run script with arguments
  • Next by thread: Re: Run script with arguments
  • Index(es):
    • Date
    • Thread