2

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.

  • Don't have answer to your question but what you are trying to achieve can be done without a second copy of the app. See here – Vic Jul 6 '14 at 21:16
1

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.

0

The main Problem is that Apple Script Editor doesn't know any of the Names "App" nor "App 2" so if you run the script it asks you to select where App is stored and then replaces "App" with the Actual Name of the Application. This also happens for "App 2".

So if you two times select the same Application (which is what you're trying to do, according to your mentions) it will both times remove the Names "App" and "App 2" with the same Name of the Actual Application.

Or if you use App as an Abbrevation for the Actual Name of the Application it knows the Application in First Statement but not in the Second so it will Ask just one time and just replace the "App 2".

To do what you want i recommend you to change your Script to something like this and try it that way (not tested):

tell application "<Name of Application>" to activate --open first Window
tell application "<Name of Application>" to activate --open second Window

tell application "System Events" to tell application process "<Name of Application>"
    set position of window 1 to {8, 22}
    set position of window 2 to {914, 22}
end tell

if this doesn't work maybe you can adopt this Script which moves two open Finder Windows Side by Side.

property monitor_width : 980
property monitor_height : 768

set the startup_disk to (path to startup disk)

tell application "Finder" activate
    set visible of (every process whose visible is true and frontmost is false) to false
    -- BOTTOM WINDOW
    set this_window to make new Finder window
    set the target of this_window to the startup_disk
    set the bounds of this_window to {0, (monitor_height * 0.55) div 1, monitor_width, monitor_height}
    set the current view of this_window to column view
    -- TOP WINDOW
    set this_window to make new Finder window
    set the target of this_window to the startup_disk
    set the bounds of this_window to {0, (monitor_height * 0.06) div 1, monitor_width, (monitor_height * 0.53) div 1}
    set the current view of this_window to column view
end tell

Source: http://hints.macworld.com/article.php?story=20011127022706921

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .