cyber10matt

Q: How to use the "click menu item" script command on a menu item for an app running under a different user?

Hey everyone, quick question.....

 

I'm trying to run this script:

 

 

tell application "System Events"

       tell process "iTunes"

                 click menu item "Start Station" of menu "Song" of menu bar item "Song" of menu bar 1

       end tell

end tell



The idea behind this is to start a station from the selected song currently playing. i know, not difficult to do manually, but I want to be able to do so without having to call the iTunes app to front. Now, this script works for my own iTunes app, but i have a second instance of iTunes running from the second user on my home computer (user2), with its own separate library and account and all. the script i have works fine for the instance of iTunes running under my user account, but i can't figure out how to specify which instance of iTunes I'd like the script to work on.




i should note as an FYI that i use--


do shell script "login -f user2 /Applications/iTunes.app/Contents/MacOS/iTunes >&-2>&- &" with administrator privileges


--to open my second instance of iTunes as user2





is there a way to change "tell process 'iTunes'" to something like "tell process 'unix ID'" and have the unix ID for each respective instance of iTunes?


lemme know if I'm not making sense.... Thanks in advance to anyone who can help






MacBook Pro with Retina display, OS X El Capitan (10.11.5), null

Posted on May 29, 2016 8:30 PM

Close

Q: How to use the "click menu item" script command on a menu item for an app running under a different user?

  • All replies
  • Helpful answers

  • by red_menace,Helpful

    red_menace red_menace May 30, 2016 8:14 AM in response to cyber10matt
    Level 6 (15,519 points)
    Desktops
    May 30, 2016 8:14 AM in response to cyber10matt

    You can target an application process by using various System Events properties, e.g.:

     

    tell application "System Events"
      tell first item of (get application processes whose unix id is 15174) -- or whatever id
        activate --> needed when using GUI scripting
        get properties
      end tell
    end tell
    

     

    Note that if you are going to use GUI scripting, the application needs to be activated in order to have a GUI to use.

  • by cyber10matt,

    cyber10matt cyber10matt May 30, 2016 9:43 AM in response to red_menace
    Level 1 (8 points)
    Mac OS X
    May 30, 2016 9:43 AM in response to red_menace

    okay thanks, i think i can get it from there for iTunes.  just another quick question.... i also have 2 instances of messages running, one for each user, signed into different apple id accounts, and i often get added to these big iMessage groups that i want a quick way to leave. i have a working script for leaving a chat in my user's message app instance. is there a way to use a similar concept like the iTunes trick but for messages on different users?

     

    From what I've noticed, i think the issue arises in specifying the specific 'window "messages" of application process "Messages"' since the system defaults to my user. is there a way to run that part as the other user specific to that user's messages instance?

     


    tell application "System Events"

           tell process "Messages"

                click button "Details" of splitter group 1 of window "Messages" of application process "Messages" of application "System Events"

     

                delay 1

     

                click button "Leave this Conversation" of scroll area 1 of pop over 1 of button "Details" of splitter group 1 of window "Messages" of application process "Messages" of application "System Events"

              end tell

    end tell

  • by red_menace,Helpful

    red_menace red_menace May 30, 2016 10:13 AM in response to cyber10matt
    Level 6 (15,519 points)
    Desktops
    May 30, 2016 10:13 AM in response to cyber10matt

    The same thing applies here - to use GUI scripting, the specific application needs to be activated and brought to the front, since that is the user interface you are scripting.

  • by cyber10matt,

    cyber10matt cyber10matt May 30, 2016 6:36 PM in response to red_menace
    Level 1 (8 points)
    Mac OS X
    May 30, 2016 6:36 PM in response to red_menace

    got it, many thanks