AppleScripts Not Running Outside Of Studio

Hi,

I have a few scripts that I run that used to work fine whenever I ran them from iTunes or as compiled applications. Now, however, the only way to get them to run is to execute them within the AppleScript studio.

Can anyone advise me as to how to investigate why this is happening? I’m an OSX newbie and want to get to grips with AS!

Cheers,
Steve

wiggles nose

magically sees your code

points to line 42

There’s your problem.

I didn’t put any specific code because all AppleScripts are affected, but if it will help, here it is :

(*
"Quick Convert" for iTunes
written by Doug Adams
dougadams@mac.com

v2.6.1 dec 31 2006
- fixed error thrown when conversion procedure is canceled

v2.6 march 24 2006
- fixed problem selecting CD playlist
- updated dialog and choose prompts to refer to import or convert depending on class of selected playlist tracks
- prevents selection of iPod or Radio playlist tracks; prevents attempt to convert URL tracks

v2.5 january 18 2006
- option to remove/delete original tracks/files
- option to convert to bookmarkable also renames AAC with "m4b" extension

v2.4 february 25 2005
- option to make tracks converted to AAC "bookmarkable"

v2.3 released may 22 '04
-- no longer works in OS 9
-- condensed code
-- more error checking

v2.2 released mar 4 '04
-- tidied up some routines
-- removed a superflous confirmation dialog


Get more free AppleScripts and info on writing your own
at Doug's AppleScripts for iTunes
http://www.malcolmadams.com/itunes/
*)

global encoderBackup -- stores name of the current Preferences-set encoder to be restored when procedure is completed (or canceled)

tell application "iTunes"
	activate
	
	-- inits
	set choose_encoder_prompt to "Convert tracks using..."
	set make_new_prompt to "Put converted tracks into new Playlist named...?"
	set my_no_button to "No, Just Convert"
	set del_opt to "Don't Delete!"
	
	set movem to false
	set bm_opt to ""
	set myEncoders to name of every encoder
	set encoderBackup to name of current encoder
	
	-- exceptions
	try
		set thisPlaylist to view of front window
	on error
		my alert_user_and_cancel("Unable to access tracks in selected playlist...")
	end try
	
	set the_source to kind of container of thisPlaylist
	
	if the_source is iPod then
		my alert_user_and_cancel("iPod tracks cannot be converted. Select some tracks in iTunes...")
	end if
	
	if the_source is radio tuner then
		my alert_user_and_cancel("Radio tracks cannot be converted. Select some tracks in iTunes...")
	end if
	
	-- which tracks
	if selection is not {} then -- it's selection
		set selectedTracks to selection
	else -- it's the whole playlist
		if thisPlaylist is library playlist 1 then -- but the WHOLE library???
			--activate
			my alert_user_and_cancel("Select some tracks first.")
		else
			set selectedTracks to (every track of thisPlaylist whose enabled is true)
		end if
	end if
	
	-- empty playlist
	if (length of selectedTracks) is 0 then ¬
		my alert_user_and_cancel("No tracks in playlist!")
	
	-- change prompts to refer to importing
	if the_source is audio CD then
		set choose_encoder_prompt to "Import CD tracks using..."
		set make_new_prompt to "Put imported tracks into new Playlist named...?"
		set my_no_button to "No, Just Import"
	end if
	
	-- choose encoder
	set myNewEncoder to (choose from list myEncoders with prompt ¬
		choose_encoder_prompt default items (encoderBackup as list) ¬
		OK button name "OK" cancel button name ¬
		"Cancel" without multiple selections allowed and empty selection allowed) as string
	if myNewEncoder is "false" then error number -128
	
	if (myNewEncoder as string) contains "AAC" then set bm_opt to button returned of (display dialog "You have selected to convert tracks to AAC. Would you also like to make these tracks \"bookmarkable\"?" buttons {"No", "Yes"})
	
	-- make new playlist?
	repeat
		set make_new to (display dialog make_new_prompt default answer ¬
			"" buttons {"Cancel", my_no_button, "OK"} ¬
			default button 3)
		
		if button returned of make_new is my_no_button then exit repeat
		
		if text returned of make_new is not "" then
			set newPlaylistName to text returned of make_new
			set movem to true
			exit repeat
		else
			set make_new_prompt to "Enter name for new playlist..."
		end if
	end repeat
	
	-- delete original tracks/files?
	if the_source is not audio CD then set del_opt to button returned of (display dialog "Remove/Delete original tracks and/or files?" buttons {"Remove Tracks & Delete Files", "Just Remove Tracks", "Don't Delete!"} default button 3)
	
	-- set new encoder
	set current encoder to encoder myNewEncoder
	
	-- convert/import selected tracks
	with timeout of 300000 seconds
		repeat with thisTrack in selectedTracks
			if class of thisTrack is not URL track then
				try
					-- convert the track
					set newT to item 1 of (convert thisTrack)
					
					-- bookmarkable?
					if bm_opt is "Yes" then my make_bookmarkable(get location of newT)
					
					-- move to new playlist?
					if movem then
						if not (exists user playlist newPlaylistName) then
							make new playlist with properties {name:newPlaylistName}
						end if
						set newPlaylist to user playlist newPlaylistName
						
						duplicate newT to newPlaylist
					end if
					
					-- delete anything?
					if del_opt starts with "remove" then
						-- delete file, remove track 
						try
							do shell script "rm " & quoted form of POSIX path of ((get location of thisTrack) as string)
							delete (some track of library playlist 1 whose database ID is (get database ID of thisTrack))
						end try
					else if del_opt starts with "just" then
						-- just remove track from iTunes library
						delete (some track of library playlist 1 whose database ID is (get database ID of thisTrack))
					end if
					
				on error m number n
					if n is -1728 then
						activate
						my alert_user_and_cancel("User Canceled.")
					end if
					my alert_user_and_cancel((n as string) & " " & m)
				end try
			end if -- no URL tracks
		end repeat
	end timeout
	
	set current encoder to encoder encoderBackup
	
	if frontmost is true then
		try
			if gave up of (display dialog "Done!" buttons {"Thanks"} ¬
				default button 1 with icon 1 giving up after 300) ¬
				is true then error number -128
		end try
	end if
end tell

to make_bookmarkable(this_file)
	tell application "Finder"
		try
			set file type of this_file to "M4B "
			set nom to (get name of this_file)
			if nom does not end with ".m4b" then
				set newnom to ((text 1 thru -((length of (get name extension of this_file)) + 1) of nom) & "m4b") as string
				set name of this_file to newnom
			end if
		on error m number n
			-- display dialog m -- debugging
		end try
	end tell
end make_bookmarkable


to alert_user_and_cancel(message)
	tell application "iTunes"
		-- restore original encoder setting
		set current encoder to encoder encoderBackup
		display dialog message buttons {"Quit"} cancel button "Quit" default button 1 with icon 0
	end tell
end alert_user_and_cancel

It’s from Doug’s AppleScripts and hasn’t been modified in any way. I run it both from iTunes and as a saved .app with iTunes running, but neither worked. Running it in Script Editor with iTunes running did work.

The same happens with all my scripts.

I’ve checked my console.log file and running my AppleScript app gives this error :

2007-03-01 22:51:26.316 NZBDownload.app[321] CFLog (21): dyld returns 2 when trying to load /System/Library/Components/AppleScript.component/Contents/MacOS/AppleScript

Any idea?

Try saving your script in your User:Library:Scripts folder. I have a few iTunes scripts that only function correctly when triggered from that location, instead of the User:Library:iTunes:Scripts folder. I have never investigated why that is, but it works for me.

You said you had a “few AppleScripts” that were acting up, and didn’t say you didn’t write them, so we can’t assume anything.

Do this, report back:

you$ cd /System/Library/Components/AppleScript.component/Contents/MacOS/ you$ ls -laF you$ lipo -info AppleScript

Okay, this is the full transcript of the session :

Last login: Fri Mar 2 18:01:56 on console Welcome to Darwin! steves-computer:~ cellgfx$ cd /System/Library/Components/AppleScript.component/Contents/MacOS/ steves-computer:/System/Library/Components/AppleScript.component/Contents/MacOS cellgfx$ ls -laF total 32 drwxr-xr-x 3 root wheel 102 Jan 22 21:52 ./ drwxr-xr-x 6 root wheel 204 Dec 20 21:43 ../ -rwxr-xr-x 1 root wheel 12512 Jan 22 21:52 AppleScript* steves-computer:/System/Library/Components/AppleScript.component/Contents/MacOS cellgfx$ lipo -info AppleScript Non-fat file: AppleScript is architecture: i386 steves-computer:/System/Library/Components/AppleScript.component/Contents/MacOS cellgfx$
All feedback appreciated!

What kind of computer ya got, chief?

Ah, that would be an HP Compaq DC7100 running OSX 10.4.8, boss… yep - it’s a Hackintosh!

Fixed that for you.