0

I need to send a Ruby script from a Linux box to a remote Mac Mini to open and close an application.

I’m not too familiar with Ruby, mostly AppleScript. Is there a way to embed my AppleScript into the Ruby script? Or is there a way to use just Ruby?

Here is the AppleScript I want to send:

cat  osascript -e 'tell application "Finder" of machine "eppc://USERNAME:PASSWORD@IP" open file "Macintosh HD:Applications:Kodi" end tell'
foo
  • 3,171
  • 17
  • 18
David
  • 1
  • You want to use Ruby to send the command? What have you tried? There are many ways to move a script to another machine and then launch it, so we need to know what protocol(s) you have available to you, such as FTP, SFTP, SSH, etc., because those determine how you move the file and execute it. As is there are a lot of unknowns and it'd take a book to cover the possibilities making this question WAY too broad. – the Tin Man Apr 15 '15 at 21:37
  • I haven't tried anything yet. Im trying to gather a little more info so I know I'm doing the right thing. As I said, I'm not familiar with any scripting outside of applescript. This is what I got from the company I purchased the Linux box through "sclibridge is a command line program on the host used to interact with the Savant control system for advanced customization." – David Apr 15 '15 at 21:50
  • Sorry for the lack of info. I'm a newbie lol. SSH is I believe the protocol they are using. Everything else they described to me about adding scripts to the system was using SSH. – David Apr 15 '15 at 21:54
  • They also sent this to me. – David Apr 15 '15 at 21:57
  • Smart Host (Linux OS) Location: /usr/local/bin/sclibridge Custom scripts and workflows need to be aware of this difference. You can use a common UNIX utility called 'uname' to determine which platform your script is running on and adjust accordingly. – David Apr 15 '15 at 21:58
  • #!/usr/bin/perl -w $osType = `uname`; chomp($osType); $sclibridge = undef; if($osType eq "Linux OS") { print "Running on Linux\n"; $sclibridge = "/usr/local/bin/sclibridge"; } elsif($osType eq "Mac OS") { print "Running on Darwin\n"; $sclibridge = "/Users/RPM/Applications/RacePointMedia/sclibridge"; } else { print "Running on Unknown: $sclibridge\n"; } – David Apr 15 '15 at 21:58
  • Don't add that information as a comment, edit your question and add that information, formatting it for readability. Comments are for... comments. – the Tin Man Apr 15 '15 at 23:56

2 Answers2

0

I found the script below at "Calling Applescript from Ruby."

def osascript(script)
  system 'osascript', *script.split(/\n/).map { |line| ['-e', line] }.flatten
end
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Antarr Byrd
  • 24,863
  • 33
  • 100
  • 188
  • 1
    Don't say "here". Instead, give people some information about where they'll land if they click the link. It's a kinder and gentler way to use hypertext. – the Tin Man Apr 15 '15 at 21:39
0

OP's question is very poorly phrased. From a bit of web searching:

Savant is a home automation system that's hosted on OS X. Unfortunately, the website is all flash and no substance, so I gave up looking for documentation there.

scli is a command line-based remote management program, used to control networked devices such as routers (and, presumably, a headless Mac Mini running a Savant server) via SNMP. Presumably sclibridge is a vendor-specific implementation; it's not a common term.

Whether scli[bridge] is used to control Savant directly is unclear, but I'm guessing probably not: it seems a bit low-level and general-purpose for that, so may just be for managing the Mac itself. It may well be that it includes an option for sending shell commands to the remote machine, avoiding the need to hop between scli and ssh all the time, but I didn't bother reading up in detail.

Quite how the OP got from there to wanting to run Ruby scripts I don't know, nor why their example code wants to talk to their Mac via Remote Apple Events, which aren't available on Linux. I suspect it's a mess of confusion largely due to lousy vendor docs.

At any rate, assuming they can use scli or ssh to run remote *nix commands, the simplest thing would be to add a bunch of executable AppleScripts to the Mac which the Linux box can then remote-execute just as it would any other shell command. e.g. Save the following as a plain-text (uncompiled AppleScript) file named kodi-remote:

#!/usr/bin/osascript

on run argv 
    -- argv : list of string -- any arguments to `kodi-remote` command

    if argv is {} or item 1 of argv is "help" then
        log "Usage: kodi-remote [ run | quit | help ]"
        return
    end if

    set cmd to item 1 of argv
    if cmd is "run" then
        tell application "Kodi" to run
    else if cmd is "quit" then
        tell application "Kodi" to quit
    else
        error "Unknown command: " & cmd number 1
    end if
end run

Use chmod +x kodi-remote to make it executable and put it somewhere that the remote shell can find it (e.g. /usr/local/bin).

You can test it locally by opening a new window in Terminal.app and running:

kodi-remote run
kodi-remote quit

The same commands should then work in whatever you use to run remote shell commands on the Linux box.

foo
  • 3,171
  • 17
  • 18