• 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: Compiling scripts that control applications that aren't installed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Compiling scripts that control applications that aren't installed


  • Subject: Re: Compiling scripts that control applications that aren't installed
  • From: kai <email@hidden>
  • Date: Thu, 17 Feb 2005 06:41:24 +0000


On Tue, 15 Feb 2005 22:31:48 -0500, Kevin Smith wrote:

I'm trying to write some scripts that control applications that aren't currently installed on my machine. So every time I compile the script, it brings up the application chooser dialog for me to point it to the application. I just want it to let me compile it because I use 'if's to get around the case when the application is installed already. Is there a way around this?

Also, (I think this is related), I have a bunch of functions in this file that use iTunes and Keynote however the functions aren't called. Whenever I open this file in Script Editor, it launches iTunes and Keynote even though I haven't called any functions yet. I want it to wait until the functions are called before launching them.

I can appreciate the concern raised by Dave Balderstone about how you could ensure the correct functioning of a script produced in this way. (I doubt that I'd feel comfortable about distributing even the simplest script if I couldn't test it properly first.) However, let's leave that question aside for a moment and assume that you have some way of ensuring that the code for each application is viable.


As you've discovered, some applications are launched when a script is compiled - which can occur either when compiling manually or when a script is opened in Script Editor. (This allows access to the target application's dictionary - so that the script can be saved as raw code, but is presented to us in human-readable form.)

If we open the following script before launching the target application, iTunes will launch automatically - before the script appears in Script Editor:

-------------

to pick(l, t)
tell (choose from list l with prompt "Choose a " & t & ":") to if it is not false then return item 1
error number -128
end pick


tell application "iTunes"
	set p to my pick(name of playlists whose size > 0, "playlist")
	set t to my pick(name of playlist p's tracks, "track")
	play track t of playlist p
end tell

-------------

Even if we refer to the application indirectly, we'll need a 'using terms from' statement to allow the script to compile - and that will also prompt a launch of the application:

-------------

to pick(l, t)
tell (choose from list l with prompt "Choose a " & t & ":") to if it is not false then return item 1
error number -128
end pick


set iTunes to "iTunes"
using terms from application "iTunes"
	tell application iTunes
		set p to my pick(name of playlists whose size > 0, "playlist")
		set t to my pick(name of playlist p's tracks, "track")
		play track t of playlist p
	end tell
end using terms from

-------------

One way around this might be to convert the script to text, and then run it using the 'run script' command:

-------------

run script "to pick(l, t)
tell (choose from list l with prompt \"Choose a \" & t & \":\") to if it is not false then return item 1
error number -128
end pick


tell application \"iTunes\"
	set p to my pick(name of playlists whose size > 0, \"playlist\")
	set t to my pick(name of playlist p's tracks, \"track\")
	play track t of playlist p
end tell"

-------------

However, this can slow things down somewhat.

Another approach is one that came up in my last reply to you (Re: Minimize all windows of an application?). By using raw codes, instead of application-specific keywords, the compiler should not have to perform any translation:

-------------

to pick(l, t)
tell (choose from list l with prompt "Choose a " & t & ":") to if it is not false then return item 1
error number -128
end pick


set iTunes to "iTunes"
tell application iTunes
set p to my pick(name of (every «class cPly» where its «class pSiz» > 0), "playlist")
set t to my pick(name of «class cPly» p's every «class cTrk», "track")
«event hookPlay» «class cTrk» t of «class cPly» p
end tell


-------------

---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Button that seems to be clicked in UI scripting, but isn't?
      • From: Richard Rönnbäck <email@hidden>
  • Prev by Date: Re: do shell script without blocking?
  • Next by Date: Date handlers
  • Previous by thread: ANN: Toggle Guest Access
  • Next by thread: Button that seems to be clicked in UI scripting, but isn't?
  • Index(es):
    • Date
    • Thread