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

Run script with arguments


  • Subject: Run script with arguments
  • From: Nicola Vitacolonna <email@hidden>
  • Date: Mon, 29 Dec 2014 17:16:22 +0100

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


 _______________________________________________
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: Deivy Petrescu <email@hidden>
  • Prev by Date: Re: [ANN] ASObjC Explorer update
  • Next by Date: AUTO: Allyn Martin is out of office.
  • Previous by thread: Re: [ANN] ASObjC Explorer update
  • Next by thread: Re: Run script with arguments
  • Index(es):
    • Date
    • Thread