tell application automatically changes on save as app?

Alright.

I have an applescript that automatically sends information about my current iTunes track to two seperate Ventrillo programs. When I first ran it from the script editor, it worked fine, great, perfect. As soon as I saved it as an application and then ran it, however, somehow it automatically changed the script! It opened the wrong copy of Ventrillo first, then gave me an error.

So, I reopened the script to see what happened, and low and behold, it changed the name of the application in one of my instructions.

tell application “Ventrilo” magically turned into tell application “TeamVent”! Can anyone give me some insight on exactly how to tell Applescript to, well, just run the script that I told it to instead of it’s own version? I mean, what the hell :slight_smile:

Here’s the script before I save it (the important part is near the end):


(*
"Current to Clipboard" for iTunes
written by Doug Adams
dougadams@mac.com

v1.5 September 23 2004
-- handles tracks in streams better
-- generally updated for modern iTunes

v1.0 Novemeber 13, 2001
-- initial release

Get more free AppleScripts and info on writing your own
at Doug's AppleScripts for iTunes
http://www.malcolmadams.com/itunes/
*)
tell application "iTunes"
	if player state is not stopped then
		set ct to current track
		set station_name to ""
		set {nom, art, alb} to {"", "", ""}
		
		tell ct
			try
				if artist is not "" and artist is not missing value then
					set art to (" by " & artist)
				end if
			end try
			try
				if name is not "" then
					set nom to name
				else
					set nom to "unknown"
				end if
			end try
			try
				if album is not "" then
					set alb to ("Album: " & album)
				else
					set alb to "Album: Unknown"
				end if
			end try
		end tell
		-- nevermind all that if I can get radio stream info
		-- also, current stream title may not return a value that works with this parsing
		try
			if (class of ct is URL track) and (get current stream title) is not missing value then
				set station_name to (nom & " - ") -- you can use this if you want
				set {art, nom} to my text_to_list((get current stream title), " - ")
				set art to " by " & art
			end if
		end try
		
		-- basic info (feel free to format your own message!)
		set the clipboard to (station_name & "\"" & nom & "\"" & art)
		tell application "Ventrilo" to activate  <------HERE'S WHAT PART GETS CHANGED
		tell application "System Events"
			tell application process "Ventrilo"
				click button "Comment" of window "Ventrilo"
				delay 1
				click menu item "Paste" of menu 1 of menu bar item "Edit" of menu bar 1
				delay 1
				click button "OK" of window "Comment"
			end tell
		end tell
		set the clipboard to alb
		activate application "TeamVent"
		tell application "System Events"
			tell application process "TeamVent"
				click button "Comment" of window "Ventrilo"
				delay 1
				click menu item "Paste" of menu 1 of menu bar item "Edit" of menu bar 1
				delay 1
				click button "OK" of window "Comment"
			end tell
		end tell
		
	end if
end tell

on text_to_list(txt, delim)
	set saveD to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to {delim}
		set theList to every text item of txt
	on error errStr number errNum
		set AppleScript's text item delimiters to saveD
		error errStr number errNum
	end try
	set AppleScript's text item delimiters to saveD
	return (theList)
end text_to_list


Now, here’s the script AFTER I save it as an application:


....clipped....
		
		-- basic info (feel free to format your own message!)
		set the clipboard to (station_name & "\"" & nom & "\"" & art)
		tell application "TeamVent" to activate  <--------CHANGED TO "TEAMVENT".
		tell application "System Events"
			tell application process "Ventrilo"
				click button "Comment" of window "Ventrilo"
				delay 1
				click menu item "Paste" of menu 1 of menu bar item "Edit" of menu bar 1
				delay 1
				click button "OK" of window "Comment"
			end tell
		end tell
		set the clipboard to alb
		activate application "TeamVent"
		tell application "System Events"
			tell application process "TeamVent"
				click button "Comment" of window "Ventrilo"
				delay 1
				click menu item "Paste" of menu 1 of menu bar item "Edit" of menu bar 1
				delay 1
				click button "OK" of window "Comment"
			end tell
		end tell
		
	end if
end tell

...clipped...

Since I had to call specific application processes, I had to change the process names of one of the duplicate Ventrilo programs. I did this by changing the engine application in the MacOS folder under Show Package Contents, and then updating the Info.plist file in the same package folder. I also changed the name of the package app. They were all changed to TeamVent.

The other Ventrilo application was left alone with the name Ventrilo for both the appllication name and the application process name.

So, yeah, if anyone could help me, that’d be awesome because I’m sure stuck on what to do now.

Thanks!

AppleScript: 1.10.6
Browser: Firefox 1.5.0.7
Operating System: Mac OS X (10.4)

This problem is a side effect of how AppleScript stores references to applications.

Even though you write the script to target an application by name, when the script is saved AppleScript saves the application [i]signature[/] rather than the name. In this way the script can be transferred to someone else’s machine where the application might be “Appname 1.0” or some foreign language translation of the name which differs from the app name on your machine.

The problem comes along when you have two applications with the same signature. Ideally this should never happen since application developers usually register a unique signature for each application. However, home-grown applications, especially AppleScript-based applications, often have the same signature.

When you open the script in Script Editor there’s a chance that AppleScript will choose the ‘wrong’ app because it doesn’t know any better (as far as it is concerned the app has the same signature and therefore it is valid).

This should be less of a problem now than it was in the pre-Mac OS X days since all applications used a 4-character signature. Clearly with such a finite number of permutations conflicts did arise. Modern applications, though, should use a different system more along the lines of the com.vendor.product namespace (like com.apple.safari, com.barebones.bbedit, etc.) where conflicts shouldn’t arise at all.

The only real solution to this is to ensure that your applications use distinct signatures. I don’t know what ‘Ventrilo’ or ‘TeamVent’ are - if they’re applications you’ve written you can (and should) give them different signatures. If they’re writtenby third parties you should contact them, tell themto get their act together then update to newer versions that have correct signatures.

Thanks for the reply!

Both the applications are called Ventrilo, a Skype-like VoIP application mostly used by gamers to communicate with each other and such.

The whole problem was that they are two of the exact same application. I needed to run two copies of the Ventrilo application simultaniously to achieve what I wanted. I don’t know if I installed them right… I just selected the Ventrilo.app packaged and hit Duplicate to get a second copy, since it seemed like the Ventrilo installer would have just overwrote my original copy if I went that route to get a second copy. But in order to address them in AppleScript, I needed them to act like two seperate applications, so I did my best to make one of the apps seem like it was named TeamVent.

I’m going to go try changing the info.plist file for the com.ventrilo.whatever of one of the applications and see what happens. If that’s even the correct way to go about it, I have no idea…