0

I set up my old laptop as a media server and created a mac application in AppleScript that would remotely restart or shutdown the mac depending on which button was pressed, using this code:

tell application "Finder" of machine "eppc://USERNAME:PASSWORD@MYSERVER"
    shut down
end tell

It's super simple, and was easy to write, but now I want to create an iPad app that can accompany the mac one. Ideally, I'd like to use AppleScript as, like I said, it's very simple, but I feel like that's not an option.

What are some other ways to do this? Where I would click a button, then it would connect to my mac and either shutdown or restart.

I feel like the best way would be to use SSH, and right now I'm looking at https://github.com/x2on/libssh2-for-iOS. Any other ideas?

Charlie
  • 11,380
  • 19
  • 83
  • 138
  • possible duplicate of [Best way to communicate iphone with mac?](http://stackoverflow.com/questions/1200660/best-way-to-communicate-iphone-with-mac) See also: [How do I send a command to a Mac](http://stackoverflow.com/questions/2272253/how-do-i-send-a-command-to-a-mac-via-wifi-from-an-iphone) and [Send messages between iPhone and Mac](http://stackoverflow.com/questions/5863218/send-messages-between-iphone-mac) – jscs Apr 18 '12 at 00:06
  • While those might cover what I'm trying to do, I'm also wondering specifically if applescript can be used to do this, making it in fact, not a duplicate. Furthermore, one of your links deals with it being over the same network, but that was not specified in my post. – Charlie Apr 18 '12 at 00:12
  • 2
    Your post says "What are some other ways to do this?" and "My other possible idea was to use SSH". I'd suggest making your question more specific, which may require doing some legwork of your own. – jscs Apr 18 '12 at 00:17
  • Made it more specific, I believe. Also found possible way to accomplish this, now I'm looking for alternatives or better ways. – Charlie Apr 18 '12 at 12:06

1 Answers1

1

Okay, just to brainstorm.... Dropbox is a great way to share content among machines, but it's also a pretty darn decent communication mechanism.

I use Dropbox to fire up (legal only!) bittorrent downloads on my home machine by setting up my torrent client to watch a dropbox folder for incoming .torrent files. I can then save .torrents into that directory on any machine I have Dropbox on, or in principle from a browser on my iOS devices that could share to Dropbox, and ta-da, instant remote kickoff. I can sit on another machine, save a .torrent to that directory, watch its file extension change to .torrent.imported, and know that when I get back to my main machine, that thing will be downloaded.

You could use folder actions or a cron job to watch a certain Dropbox folder for commands, and then put files into that folder that trigger those scripts to perform certain behaviors. Dropbox has a very nice iOS client library, making it totally possible to store stuff to Dropbox from a custom app.

Dan Ray
  • 21,623
  • 6
  • 63
  • 87
  • So... you could say, press a button in the app which would upload a file to my dropbox, then a folder action could look for it, and open it. In the script, it could then open a local script, which would wait a few seconds to restart or shutdown, and then delete the dropbox file? I kind of like this idea, but I feel like there would be too many problems, like, what if multiple copies get uploaded at once? – Charlie Apr 18 '12 at 12:30
  • Well, you'd define a specific filename to trigger a specific piece of functionality. You know, you could also have one file in which you write one-liner commands. The folder action could watch for size change on that file, open it up, see what you've said, clear out the file, and perform the action. Either way, you want ONE file that does the business, because otherwise, yeah, this is race-condition city. – Dan Ray Apr 18 '12 at 13:00
  • Another possibility would be to code it in Phonegap in JS, and have it send an email, which the computer reads, then runs a script depending on the subject. Do you have other ideas along those lines? – Charlie Apr 18 '12 at 14:25