Mac Commander Plugin

Posted on
Sun May 22, 2016 10:14 am
Colorado4Wheeler offline
User avatar
Posts: 1130
Joined: Jul 20, 2009
Location: Colorado

Mac Commander Plugin

Introduction

This plugin allows you to perform actions on any Mac in your network, whether it is the Indigo server or not. What you can do is only limited to what Applescript can do on the given machine.

At its core this plugin is a Python program that executes Applescript commands on your desired machine. While this is easily accomplished using Indigo's scripting, I wanted to be able to take it a step further by having an On/Off state associated with the command.

For example (and why I built this in the first place): I have Plex running on one of my Macs in the house (not the Indigo server) and wanted to be able to turn the Plex Server on and off at will. I accomplished this easily with some Indigo scripting but it was just firing into the blind. What this app does is allow me to assign an "On" command (start Plex server), and "Off" command (stop Plex server) and a "Polling" option to see if Plex server is running or not and dynamically turn my "device" on or off as a result.

Like most of my plugins, this was centered around it's ability to be useful in a control page, so a single button can turn commands On and Off via toggle and display their On/Off state as a change in the button graphic.

This concept can be expanded to any program or any script. The only thing required is that you have enabled remote access in your Mac's sharing and know the IP address, username and password.

Download and Installation

The first thing you need to do is to enable "Remote Login" on any Mac that you want to control with this plugin. This allows Applescript to execute remote commands:

Screen Shot 2016-05-22 at 9.29.22 AM.png
Screen Shot 2016-05-22 at 9.29.22 AM.png (17.34 KiB) Viewed 3062 times


Install the plugin according to the Indigo documentation.

Once installed you create a device for each command set you want to manage and set the options.

Download Plugin (Indigo File Library)

Release Notes

  • May 22, 2016 (1.0.0):
    • Initial release

Plans For Future Releases

  • Only execute app-based commands if a user is logged in
  • Add additional polling options
  • Remotely shutdown or restart a computer

Configuration and Use

The options are pretty straightforward and relatively dynamic. Keep in mind that you will start off in Indigo with a fairly small configuration window but as you select options you may have to scroll down in the window to see them.

When you first add the device you get a basic configuration window with some sample data:
Screen Shot 2016-05-22 at 9.47.38 AM.png
Screen Shot 2016-05-22 at 9.47.38 AM.png (50.56 KiB) Viewed 3064 times


Selecting "Run actions on Indigo server" means you will not need to connect to a remote computer (nor does the Indigo server need to have Remote Login enabled in sharing), otherwise you will want this unchecked and supply the IP address and credentials of the computer you are commanding.

If you enable polling you will see the following:
Screen Shot 2016-05-22 at 9.50.55 AM.png
Screen Shot 2016-05-22 at 9.50.55 AM.png (28.03 KiB) Viewed 3064 times


There is currently only one method and it's selected as "Application is Running" by default. The proper application name should reflect what the icon says in your Applications folder, with no .app extension. Polling interval is how many seconds Indigo will check to see if that app is running or not (if it is the device is set to On, if not then it's set to Off). The final polling method parameter is when you want to poll that device - you can have it Always poll 24/7, only poll when the device is On or only poll when it's Off. While the plugin is not memory or time hungry, there is no need to constantly poll something if you only want to do so when it's on or off. Polling is optional, if you don't provide it then the device will only turn On and Off if you do so manually.

Both the On and Off actions configure the same way and neither is required. This is to say that you can define only an On or only an Off if you choose, but you are not required to have both. This lets you just have a static remote command that you execute at will rather than worrying about on/off states. The options are:
Screen Shot 2016-05-22 at 9.56.20 AM.png
Screen Shot 2016-05-22 at 9.56.20 AM.png (27.34 KiB) Viewed 3064 times


The options are fairly self explanatory. Depending on which option you choose will add additional fields in the configuration for you to fill in:
  1. Run Application: Provide the proper name for the app to run and the app must reside in your Applications folder. This can also be a compiled Applescript program (see advanced below)
  2. Quit Application: Same field as Run Application
  3. Display a Message: Currently not available, I'm working on a few bugs on this
  4. Sleep: Put the computer to sleep, no additional options but I may add a timer to this later
  5. Start Screensaver: Start the screensaver, no additional options
  6. iTunes: Another menu of possible iTunes commands will appear in the configuration, the only one of note is the Playlist, in which case you will need to provide the exact name of the playlist to play (useful if you use Airfoil and want to automate that a bit more)

Advanced

There are some things that either don't work well with normal Applescript commands or don't like to be done remotely (i.e., stopping Plex Server). In these cases you simply write the Applescript command(s) that do what you want to do, save that Applescript as a compiled application in your Applications folder and tell the plugin to execute that compiled Applescript.

For example, I wanted to stop my Plex server so I wrote and compiled the following script on that Mac called "Stop Plex.app" and saved it to my Applications folder on the computer with Plex Media Server:
Code: Select all
tell application "Plex Media Server" to quit


Limitations

The plugin is a work in progress so not every possible outcome is accounted for. For example I have not yet added a check to see if there is a person logged into the Mac you want to command (although it is planned), so you will need to make sure the Mac is logged in before you try to command it.

Currently the polling has only one method, to see if an application is running. While this may be limiting, you can create a compiled Applescript on the destination Mac that will activate or quit depending on your own circumstances, check for THAT app's running status and use that. I'm sure there are dozens of ways I can poll for a particular situation, so tell me what you would like to poll and I'll see if I can build it in.

I threw in some iTunes commands just because I could (and I find them useful in my own environment) so there wouldn't be just a single task this plugin can do. If you have ideas of things you would like the plugin to do natively let me know and I'll see about expanding the functionality of the plugin to incorporate that.

Examples of Use

  • Example: When the office light is turned off start the password protected screensaver on the computer
    • Computer: Turn on Remote Login (see instructions above) in Preferences->Sharing on the office computer
    • Device: Create Mac Command device where the "On Action" is "Start Screensaver" and the IP address, username and password are set for the office computer
    • Trigger: When office light becomes Off turn On Mac Command device

My Modest Contributions to Indigo:

Homebridge Buddy | Room-O-Matic | Smart Dimmer | Scene Toggle | Mac Commander | Security Manager | Device Extensions | LCD Creator | Control Page Keypad | Powermiser

Check Them Out Here

Posted on
Mon May 23, 2016 10:04 am
Colorado4Wheeler offline
User avatar
Posts: 1130
Joined: Jul 20, 2009
Location: Colorado

Re: New Plugin: Mac Commander

A lot of folks may not have seen this get posted so I'm replying to bump it in the forums so you know it's out there :).

My Modest Contributions to Indigo:

Homebridge Buddy | Room-O-Matic | Smart Dimmer | Scene Toggle | Mac Commander | Security Manager | Device Extensions | LCD Creator | Control Page Keypad | Powermiser

Check Them Out Here

Posted on
Tue May 24, 2016 12:15 am
Coolcaper offline
Posts: 192
Joined: Aug 30, 2013
Location: Australia

Re: New Plugin: Mac Commander

Awesome! Thanks for the plugin!

Posted on
Tue May 24, 2016 2:52 am
rhanson offline
Posts: 118
Joined: Apr 30, 2013

Re: New Plugin: Mac Commander

To determine if (this) Mac is logged in:

Code: Select all
import Quartz
d = Quartz.CGSessionCopyCurrentDictionary()
e = (d and
       d.get("CGSSessionScreenIsLocked", 0) == 0 and
        d.get("kCGSSessionOnConsoleKey", 0) == 1)
print "1" if e else "0"

Posted on
Tue May 24, 2016 7:27 am
Colorado4Wheeler offline
User avatar
Posts: 1130
Joined: Jul 20, 2009
Location: Colorado

Re: New Plugin: Mac Commander

rhanson wrote:
To determine if (this) Mac is logged in:


Thank you for the suggestion :). I actually have a method already I just wanted to get the non-checking version out into the world to see if there were any other issues people have before I complicated it a bit more :).

My Modest Contributions to Indigo:

Homebridge Buddy | Room-O-Matic | Smart Dimmer | Scene Toggle | Mac Commander | Security Manager | Device Extensions | LCD Creator | Control Page Keypad | Powermiser

Check Them Out Here

Posted on
Tue May 24, 2016 11:47 am
Swancoat offline
Posts: 403
Joined: Nov 20, 2009
Location: Houston

Re: New Plugin: Mac Commander

This is super cool, I have two computers in my office and a simple trigger that wakes the screens or sleeps the screens when I turn the light on or off. However, doing it on the non-Indigo Mac over the network required leaving a script sitting on that machine.

This method is a bit more elegant I think, and also encourages me to do something similar with my wife's computer.

http://nerdhome.jimdo.com

Posted on
Tue May 24, 2016 12:33 pm
Colorado4Wheeler offline
User avatar
Posts: 1130
Joined: Jul 20, 2009
Location: Colorado

Re: New Plugin: Mac Commander

Thanks :). There are a lot more things I can do with it but am waiting for people to say "can I do....." before I implement them all, otherwise I'll be updating that plugin until the cows come home :).

My Modest Contributions to Indigo:

Homebridge Buddy | Room-O-Matic | Smart Dimmer | Scene Toggle | Mac Commander | Security Manager | Device Extensions | LCD Creator | Control Page Keypad | Powermiser

Check Them Out Here

Posted on
Tue May 24, 2016 2:48 pm
Coolcaper offline
Posts: 192
Joined: Aug 30, 2013
Location: Australia

Re: New Plugin: Mac Commander

I know it can be done via AppleScript by running an application but maybe a shutdown command to another Mac? Would be a little more elegant

Posted on
Fri May 27, 2016 11:19 am
Colorado4Wheeler offline
User avatar
Posts: 1130
Joined: Jul 20, 2009
Location: Colorado

Re: New Plugin: Mac Commander

Coolcaper wrote:
I know it can be done via AppleScript by running an application but maybe a shutdown command to another Mac? Would be a little more elegant


Good suggestion, I've added it to the "Plans For Future Releases" in the original post. Alternatively you can still use this plugin to do that, the only difference is that you need to write the Applescript on the computer you want to shut down and save it as an application and save it to the Applications folder, then you can configure Mac Commander to simply run that program. See the above example about shutting down Plex.

My Modest Contributions to Indigo:

Homebridge Buddy | Room-O-Matic | Smart Dimmer | Scene Toggle | Mac Commander | Security Manager | Device Extensions | LCD Creator | Control Page Keypad | Powermiser

Check Them Out Here

Posted on
Thu Aug 25, 2016 5:57 pm
durosity offline
User avatar
Posts: 3075
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Re: Mac Commander Plugin

Feature request... wake screen option. Basically I want a trigger that if the motion sensor in the study detects movement it'll automatically wake the screens on my Mac before I sit down.

Also on a side note minor bug.. going to Plugins > EPS - Mac Commander > About EPS - Mac Commander v1.0.0 takes you to the plugin developer example page rather than this forum :)

Computer says no.

Posted on
Thu Aug 25, 2016 6:07 pm
Colorado4Wheeler offline
User avatar
Posts: 1130
Joined: Jul 20, 2009
Location: Colorado

Re: Mac Commander Plugin

durosity wrote:
Feature request... wake screen option.

Yup, that's already on the list for the next release, along with putting that computer to sleep as well :).

durosity wrote:
About EPS - Mac Commander v1.0.0 takes you to the plugin developer example page

Yea, the early releases all had that because it's sort of a cart and horse situation, you can't really post a forum page before you have a plugin and can't really upload the plugin without the forum page, so one has to give and that was it :). Generally I try to fix that either right after creating the forum page that I can link to or when the next release comes out. Regardless, duly noted.

My Modest Contributions to Indigo:

Homebridge Buddy | Room-O-Matic | Smart Dimmer | Scene Toggle | Mac Commander | Security Manager | Device Extensions | LCD Creator | Control Page Keypad | Powermiser

Check Them Out Here

Posted on
Thu Aug 25, 2016 6:29 pm
durosity offline
User avatar
Posts: 3075
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Re: Mac Commander Plugin

Cool :D. So uh.. when's the wife next going away so you'll have time to do these things? ;)

Computer says no.

Posted on
Thu Aug 25, 2016 6:48 pm
Colorado4Wheeler offline
User avatar
Posts: 1130
Joined: Jul 20, 2009
Location: Colorado

Re: Mac Commander Plugin

Of my 15 published plugins I've either completely rewritten, seriously updated or patched up 9 of them and am running them on my Indigo now. Additionally I have 4 more new ones ready to go - including a pretty major one and another that I think will satisfy and oft-requested feature.

Mac Commander has not made it to that list yet because the big plugin(s) have taken the vast majority of my Indigo programming time. That being said, I will start re-writing the older plugins pretty soon - I wrote an entire back-end engine for my plugins to sit on and I want all of them on it.

But, alas, I'm not uploading any of this yet because I know I7 is likely going to be released soon and I don't know what, if anything, might break my plugins and I really don't want a flood of problems to deal with in a short span of time :). So, until I see what API changes I7 might bring I'm not releasing anything just yet.

Oh, and my wife has been gone two weeks so I've been doing a LOT of Indigo coding lately :).

My Modest Contributions to Indigo:

Homebridge Buddy | Room-O-Matic | Smart Dimmer | Scene Toggle | Mac Commander | Security Manager | Device Extensions | LCD Creator | Control Page Keypad | Powermiser

Check Them Out Here

Posted on
Thu Aug 25, 2016 7:02 pm
durosity offline
User avatar
Posts: 3075
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Re: Mac Commander Plugin

Oooh intriguing! We'll have to make sure your wife is out of town when i7 appears.

(Just remember Indigo 7 doesn't actually exist. I know because Jay FaceTimed me and said "I'm on the beach chillin' instead of codin' " while sipping on his 7th Pina Colada. Yes, jay does actually drink Pina Coladas! )

Computer says no.

Posted on
Thu Aug 25, 2016 7:07 pm
Colorado4Wheeler offline
User avatar
Posts: 1130
Joined: Jul 20, 2009
Location: Colorado

Re: Mac Commander Plugin

durosity wrote:
Just remember Indigo 7 doesn't actually exist.

I choose to believe in unicorns, pots of gold at the end of the rainbow, a place where freedom exists but without taxes and the release of Indigo 7.

FAITH:
n. Confident belief in the truth, value, or trustworthiness of a person, idea, or thing.
n. Belief that does not rest on logical proof or material evidence. See Synonyms at belief, trust.
n. Loyalty to a person or thing; allegiance: keeping faith with one's supporters.

My Modest Contributions to Indigo:

Homebridge Buddy | Room-O-Matic | Smart Dimmer | Scene Toggle | Mac Commander | Security Manager | Device Extensions | LCD Creator | Control Page Keypad | Powermiser

Check Them Out Here

Who is online

Users browsing this forum: No registered users and 1 guest