Getting Trigger's Device via Applescript

Posted on
Thu Oct 08, 2015 12:24 am
chrisfromthelc offline
Posts: 38
Joined: Oct 08, 2014

Getting Trigger's Device via Applescript

I want to be able to write a single "status" Applescript to rule them all, so that when something is triggered (for example, a lamp gets turned on), I can take that "unknown" devices that changed status, and use the name in an Applescript (to send an iMessage).

I have everything working, except how to detect the name of the device. How can I reference this name without hard coding the device reference into the script?

Posted on
Thu Oct 08, 2015 10:35 am
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Getting Trigger's Device via Applescript

How is the AppleScript being run? Not sure I'm following the flow.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Oct 08, 2015 11:05 am
chrisfromthelc offline
Posts: 38
Joined: Oct 08, 2014

Re: Getting Trigger's Device via Applescript

I'm running it as an action of a trigger (Applescript currently embedded, but I'd like to move it to an external script). Is there any way to pass the trigger's device name to the script? In this example, the type is Device State Changed, so I wanted to grab whatever device is selected that the trigger is watching.

Current code:
Code: Select all
set targetMessage to "The lamp is on!" # here's where I'd like that variable to be able to go
tell application "Messages"
   set targetService to 1st service whose service type = iMessage
   set targetBuddy to buddy "+15558675309" of targetService
   send targetMessage to targetBuddy
end tell

Posted on
Thu Oct 08, 2015 4:52 pm
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Getting Trigger's Device via Applescript

No, that's not possible. If your triggering event is just a single device however then you already know what the device is, right?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Oct 08, 2015 5:33 pm
chrisfromthelc offline
Posts: 38
Joined: Oct 08, 2014

Re: Getting Trigger's Device via Applescript

I do, but I'd rather be able to point to a single "master" script and let it plug in the appropriate device name, but I guess that's not possible.

Posted on
Thu Oct 08, 2015 9:00 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: Getting Trigger's Device via Applescript

Here is how I address it: each device has a mini action set variable x to devname and calls the main action. The main action then can pick up the devname from the variable x


Sent from my iPhone using Tapatalk

Posted on
Fri Oct 09, 2015 10:45 am
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Getting Trigger's Device via Applescript

You can also make your script an AppleScript handler to which you pass the name of the device. So, create an Attachment script with your handler:

Code: Select all
on doMyNotification(deviceName)
   tell application "Messages"
      set targetService to 1st service whose service type = iMessage
      set targetBuddy to buddy "+15558675309" of targetService
      send deviceName & " is on!" to targetBuddy
   end tell
end doMyNotification


Then, in the embedded script for each trigger:

Code: Select all
doMyNotification("Device Name Here")

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Oct 09, 2015 10:02 pm
chrisfromthelc offline
Posts: 38
Joined: Oct 08, 2014

Re: Getting Trigger's Device via Applescript

I think this will work. Thanks!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 28 guests