Saving Applescript Removes Characters

applescript

I have written an Applescript to launch and position two instances of an Application. The script runs perfectly fine in the editor using this code:

tell application "App" to activate
tell application "System Events" to tell application process "App"
    set position of window 1 to {8, 22}
end tell
tell application "App 2" to activate
tell application "System Events" to tell application process "App 2"
    set position of window 1 to {914, 22}
end tell

It is not a scriptable app so I am using System events (I also changed the CFBundleName of the second app, so that it includes the 2 to differentiate the processes). This all works fine in the editor when I run it. However, when I save the script as an Application it consistently removes the "2" from "App 2" whenever I save the application, even though it compiles fine. Does anyone have any idea why this is happening; I'm fairly new to Applescript.

Best Answer

You can avoid the problem at compile by dynamically choosing the apps in system events.

tell application "System Events"
    set App1 to (first process whose name is "App")
    tell App1
        set frontmost to true
        set position of window 1 to {8, 22}
    end tell
end tell

Then do the same for App2.