sefu1947

Q: Applescript for tiling windows

I have a pretty nice script for tiling windows, partly found on the web, partly tailored myself. It works with several apps, all having the "window" command in the Standard Suite.

However, Apples "Photos" app has a limited Standard Suite, where the "window" command is absent. Therefore, tiling leads to failure. The predecessor  "iPhoto" app is fine.

Suggestions, how to deal with this problem are welcome. Will "Photos" in the near future get a more extended Standard Suite?

iMac, OS X Yosemite (10.10.5)

Posted on Oct 14, 2015 12:32 PM

Close

Q: Applescript for tiling windows

  • All replies
  • Helpful answers

  • by Old Toad,

    Old Toad Old Toad Oct 14, 2015 2:03 PM in response to sefu1947
    Level 10 (141,095 points)
    Mac OS X
    Oct 14, 2015 2:03 PM in response to sefu1947
    "Photos" app has a limited Standard Suite, where the "window" command is absent.

    What do you mean by the window command?  Is it the Windows menu that you're referring to?

    Screen Shot 2015-10-14 at 1.58.36.jpg

    Will "Photos" in the near future get a more extended Standard Suite?

    Since we're all just users like yourself here we have no idea what's in Apples future.   Tell Apple what missing features you'd like restored or new features added in Photos via https://www.apple.com/feedback/photos.html.

     

     

    OTsig.png

  • by sefu1947,

    sefu1947 sefu1947 Oct 15, 2015 1:39 AM in response to Old Toad
    Level 1 (0 points)
    Oct 15, 2015 1:39 AM in response to Old Toad

    Thanks for your reply. I will submit the matter to Apple and hope for the best .

    The "window" command refers to AppleScript. Launch "Script Editor.app"; open "Window / Library". A list of scriptable apps opens, double click one of them (f.i. TextEdit; or add an app of your liking). Then you see the available commands:

    Screenshot 2015-10-15 10.14.33.png

    At the bottom right you see "window". By this command you may order the position of a group of windows in a neat way (tiling). Unfortunately Photos lacks the majority of these commands. So, you have to resize and move this app manually, while other apps are repositioned by a button click.

  • by Jacques Rioux,

    Jacques Rioux Jacques Rioux Oct 15, 2015 7:32 AM in response to sefu1947
    Level 4 (3,408 points)
    Mac OS X
    Oct 15, 2015 7:32 AM in response to sefu1947

    Hi,

     

    No window in Standard Suite of Photos on El Capitan.

    So, you can use the GUI Scripting to set the bounds of window  :

    The ability to control the user-interface via AppleScript was determined by the state of a checkbox located in the Accessibility system preference pane, see this page -->  http://www.macosxautomation.com/mavericks/guiscripting/index.html

     

     

    Here is an example to set the bounds of an window :

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

    set {x, y, h, w} to {0, 22, 500, 500}

    set thisApp to "Photos"

    try

        tell application thisApp to set bounds of window 1 to {x, y, h, w} -- error on Photos or on some application

    on error

        tell application "System Events"

            tell window 1 of process thisApp -- GUI Scripting

                set size to {h, w}

                set position to {x, y}

            end tell

        end tell

    end try

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

  • by sefu1947,

    sefu1947 sefu1947 Oct 17, 2015 9:32 AM in response to Jacques Rioux
    Level 1 (0 points)
    Oct 17, 2015 9:32 AM in response to Jacques Rioux

    Thank you for your explanation.

    I was not aware that there is a difference between Apple scripting and Gui scripting. Anyhow, the scripts are quite similar.

    My Accessibility System Preference Pane does not show an "Enable access for assistive devices" checkbox. But since Snow Leopard I use the terminal command:

    do shell script ¬

      "touch /private/var/db/.AccessibilityAPIEnabled" password "pwd" ¬

      with administrator privileges

    I guess this yields the same result.

    I tried to add the GUI Scripting Applet, but did not find from where to obtain it. The "Script Editor.app" and the "systemUIServer.app" are checked.

    I would welcome documentation about scripting, like a "Missing Manual for scripting". But I am afraid it does not exist.

    Kind regards, Hans

  • by Jacques Rioux,

    Jacques Rioux Jacques Rioux Oct 18, 2015 7:20 AM in response to sefu1947
    Level 4 (3,408 points)
    Mac OS X
    Oct 18, 2015 7:20 AM in response to sefu1947

    Hi,

     

    sefu1947 wrote:

     

    Thank you for your explanation.

     

    I tried to add the GUI Scripting Applet, but did not find from where to obtain it. The "Script Editor.app" and the "systemUIServer.app" are checked.

     

    You must drag/drop your Applet in the "Security & Privacy" system preference pane.

     

     

    The simplest is that (the system automatically adds (script, applet or application) in the preferences):

    Run your applet.

    The system show these windows.

    infoWind1.png

    Click on the "OK" button, and click on the "Open System Preferences" button.

     

    After that, the system add the applet in the preference window  ("tilingWindows.app" in my image).

    securityAndPrivacyPref.png

     

    You need to unlock the preference pane (need an administrator password) to check your applet's checkbox.

  • by sefu1947,

    sefu1947 sefu1947 Oct 18, 2015 8:25 AM in response to Jacques Rioux
    Level 1 (0 points)
    Oct 18, 2015 8:25 AM in response to Jacques Rioux

    Hello Jacques,

    Thanks for your extended explanation. In my case the way things turn out is a little bit different. Let me share my experience. My present situation allows me to apply scripts to scriptable apps and is defined by:

    Screenshot 2015-10-18 17.06.30.png

    I want to mimic your advice, so I unchecked "Script Editor.app" and "SystemUIServer.app". In this way I hoped that your first two pictures would appear, so that I could proceed to the "Accessibility Inspector". But nothing happens after running my "tilingWindows" (no warning nor error message). After checking them again "tilingWindows" works as before.

    Of course, non-scriptable apps are not effected. But "Photos" is scriptable, at least in a limited way. However, it generates the error message (added in the script myself).

    Kind regards, Hans

  • by Jacques Rioux,

    Jacques Rioux Jacques Rioux Oct 18, 2015 4:06 PM in response to sefu1947
    Level 4 (3,408 points)
    Mac OS X
    Oct 18, 2015 4:06 PM in response to sefu1947

    Hello Hans,

     

    sefu1947 wrote:

     

    I want to mimic your advice, so I unchecked "Script Editor.app" and "SystemUIServer.app". In this way I hoped that your first two pictures would appear, so that I could proceed to the "Accessibility Inspector". But nothing happens after running my "tilingWindows" (no warning nor error message). After checking them again "tilingWindows" works as before.

    Of course, non-scriptable apps are not effected. But "Photos" is scriptable, at least in a limited way. However, it generates the error message (added in the script myself).

     

     

     

    "Accessibility Inspector" is an application from the Xcode bundle (developer tools), it is not necessary for your issue, but it is useful to inspect an UI element from an application (get attributes, actions and properties of an specific UI element, menu, button, textfield, table or other).

     

    ----

    If your script is not an Applet (an AppleScript saved as Application) or an application made by Automator (an workflow which contains an AppleScript with GUI Scripting) :

    If you run a script by selecting the script from the Script menu, you must check the "SystemUIServer.app" in "Security and Privacy" pane, that's all, you do not need anything more, see https://support.apple.com/en-us/HT202802

     

    If you run a script from a third party utility, like Alfred, FastScript, Quicksilver or others, generaly you must grant access to this utility.

     

    If you run the script from an Automator service, you must grant access to the application where you call this service.

     

    There are other more complicated possibility as running a script with GUI Scripting in an osascript command from a shell script, which I do not know the answer.

  • by sefu1947,

    sefu1947 sefu1947 Oct 19, 2015 3:53 PM in response to Jacques Rioux
    Level 1 (0 points)
    Oct 19, 2015 3:53 PM in response to Jacques Rioux

    Chapeau! The penny has dropped. I have made my first Applet. It is recognised by Accessibility and it is working for the regular scriptable apps:

    Screenshot 2015-10-20 00.43.56.png

    For Photos I am going to implement the "on error" code according to your directive. I am confident that I will be able to do so.

    Thanks again for your patience, Hans