What command do I need to launch an app on a networked machine? (shell script)

Discussion in 'Mac Programming' started by arcsbite, Nov 9, 2008.

  1. arcsbite Guest

    Joined:
    Jan 14, 2006
    #1
    ok, not sure if I even phrased that correctly.
    I owna macbook and a mac pro. both on the network.
    I wish to create a shell script that I can insert into an automator flow that will allow me to connect to my mac pro and launch itunes on the mac pro.

    did that make any sense?

    I then need another shell script to place at the end of the flow that launches itunes on my mac pro.
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    I have a pretty UNIX-centric view of the world, so I would do something like:
    ssh -f user@macproname "/Applications/iTunes.app/Contents/MacOS/iTunes &"

    Should work if you have SSH turned on on the mac pro.

    Now the issue is authentication. I (again, being more UNIX-centric than I am familiar with Apple-specific ways of doing things) would set up shared keys on both machines so you can easily access each from the other without a password. This is somewhat involved for the uninitiated, but to run an ssh command as shown above using a script (that's to say, no user interaction) you would need to do this so your script doesn't hang waiting for the password to be entered.

    If you want to take this route, and need help turning on SSH and/or setting up shared keys, let us know.

    -Lee
     
  3. arcsbite thread starter Guest

    Joined:
    Jan 14, 2006
    #3
    I think I overcomplicated things in my question, sorry.
    I currently have an automator script that will get me to the server (the Mac Pro), authenticate and connect.
    it then runs a script to sync my itunes library (so my mac pro itunes library is synced to my macbook...like it would to an ipod using

    cat
    rsync -av --force --delete --size-only ~/Music/iTunes /Volumes/Rick/Music > ~/Documents/AutomatorLogs/iTunesMSync.log

    but I then need it to launch iTunes when it finishes.
    If I try this automatically via automator it simply launches on the Pro not the remote macbook.
     
  4. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #4
    Oh. So the machine running the script/workflow is the one you want iTunes started on?

    In applescript this would be:
    Code:
    tell application "iTunes" activate
    
    Alternately, the shell command at the end of the ssh command in my previous post would do it from shell instead of applescript, but applescript is probably easier to integrate into an automator workflow.

    That applescript will not restart iTunes if it is already running, etc... so you might have to get more creative.

    -Lee

    P.S. Hm. I am getting confused. After I read your post again, i don't think this is what you need, either.

    Let's try to describe this in absolute terms. There are some computers, A and B. There may be a computer C in this setup, i am not sure.

    Where do you need to run the rsync?
    Where is the script itself running?
    Which machine do you want iTunes to open on?
     
  5. arcsbite thread starter Guest

    Joined:
    Jan 14, 2006
    #5
    looking to have itunes start on the remote machine, so my pro will currently connect to my laptop, and sync, but I need it to quit itunes on the laptop first and then open itunes once it's finished

    I ran the apple script but that just quits iTunes on my pro 9as that's where the workflow is running from

    Got

    Mac Pro - Runs Automator Script - connects to laptop - syncs - quits.

    Need

    Mac Pro - Runs automator script - connects to laptop - quits laptop itunes - syncs - opens laptop itunes - quits.
     
  6. arcsbite thread starter Guest

    Joined:
    Jan 14, 2006
    #6
    just saw your edit.

    (A) runs the script - (A) uses script to connect to (B) - (A) whilst connected to (B) syncs iTunes library from (A) to (B) - (A) then quits script and disconnects from (B)

    I need (A) to quit itunes on (B) before sync and reopen iTunes on (B) after sync.
     
  7. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #7
    OK, so we are running the workflow on the mac pro. It is running an rsync to the macbook. You now need to perform some actions on the macbook. I think my first post should be a way to do this, if not the only way. You might switch it up to use applescript instead.

    To quit iTunes on the MacBook:
    ssh -f user@macbookname "osascript -e 'tell app \"iTunes\" to quit'"

    To restart iTunes on the MacBook:
    ssh -f user@macbookname "osascript -e 'tell app \"iTunes\" to activate'"

    Again, you'd need shared keys to avoid the need for authentication.

    I'll test this in a bit, i don't want to totally freak out my wife while she's using her machine.

    -Lee

    P.S. OK, tested locally and seems to work fine... so to get this going:
    It sounds like you already have SSH/"remote login" turned on on the macbook. If not, it's under System Preferences->Sharing->Check "Remote Login".
    Then you need to setup the ssh keys, like so:

    On the mac pro (where the workflow is running) run:
    ssh-keygen -t dsa
    Use the defaults (just press enter through the whole thing). This means an empty passphrase, but this will be needed for this to work (others can fill me in if i am mistaken).

    On the mac pro, run:
    scp ~/.ssh/id_dsa.pub macbookname:.ssh/authorized_keys2
    where macbookname is the name of the macbook. This is assuming you don't already have authorized keys set up. If you do, you will overwrite it with this command.
     
  8. arcsbite thread starter Guest

    Joined:
    Jan 14, 2006
    #8
    think I'm getting in a little over my head, not getting anywhere with it.
    gonna grab some dinner then try again
    thanks for the help
     
  9. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #9
    See the edit above. You can test these commands without setting up the keys first, to make sure they do what you want.

    -Lee
     

Share This Page