i'd like to be able to open an app as a different user. For example PC1 is my main account and PC7 is my secondary one.

I can achieve the effect in terminal using

su - pc7 insert password /Applications/Application.app/Contents/MacOS/ApplicationName

How can i use the automator to make a script/app whatever that does this by a simple doubleclick?



You can not trivially launch graphical applications as another user.

A Proxy Process is Required

To launch a graphical application as another user, that user must be logged in to a graphical session and have a process running within their session able to launch your desired application.

Prior to OS X 10.9, this could be approximated via the launchctl command. See How to launch a GUI application in another user's graphical session? for a detailed discussion.

  • This is not completely true, if you are user A you can launch a graphical application as user B within the graphical session where A has logged in... – Kubuntuer82 Nov 21 at 10:22
  • @Kubuntuer82 be aware that doing this can result in the user B application running within the graphical session of user A – and thus sharing a common WindowServer session. Depending on the frameworks and services the application uses, this can lead to problems. – Graham Miln Nov 21 at 12:26

You can simply save your example as a text file adding the suffix .command or .sh to it to execute it with a double-click. AppleScript can call an .sh-script, too, with

do shell script "/path/to/yourscript.sh"

Not sure if Automator can do the same.

But su basically only works with commands not using the Aqua GUI of Mac OS X. So if you try to open an application like for example TextEdit this way, it wont be able to open a window on the Desktop.

  • su works fine with GUI apps…? – grg Mar 31 '14 at 11:57

If you were were to open AppleScript, you would use the following format:

do shell script "/usr/bin/su - " & user & " -c " & "'" & cmd & "'" with administrator privileges password "blahblah"

If you wanted to make a shell script, you'd need to chmod a+x the file and write it out like this:

#!/usr/bin/env bash
su -c "/Applications/Application.app/Contents/MacOS/ApplicationName" -s /bin/sh pc7

Or, you can write it how I would write it:

su -c "/Applications/Application.app/Contents/MacOS/ApplicationName" -s /bin/sh pc7

  1. Save the file as YourScritpt.sh
  2. Add executable permissions by typing chmod a+x YourScript.sh in Terminal
  3. Right-click the file in Finder and select 'Open with" and select "Other"
  4. Select Terminal as the application to open the file (change to All Applications)
  5. You do not need to select "Always Open With"

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