AppleScript "Application isn't running" (-600) Errors

Posted on
Mon Nov 10, 2014 12:25 pm
jay (support) offline
Site Admin
User avatar
Posts: 15209
Joined: Mar 19, 2008
Location: Austin, Texas

AppleScript "Application isn't running" (-600) Errors

[MODERATOR NOTE] we've documented a couple of workarounds to help alleviate the pain of this bug. Apple is aware of the bug but as of macOS Mojave has not fixed it. Read on for a more detailed description.

Since the release of Mac OS X 10.7 (Lion), there's been a bug with AppleScripts targeting the IndigoServer app. At first, we believed that it was because there were multiple copies of the IndigoServer.app (previous versions, etc). In Lion and Mt. Lion, finding and deleting any extra copies of the server app on all mounted volumes seemed to solve the issue.

That doesn't seem to be the case with Mavericks. We've spent several hours starting/restarting/stopping the server on the last Mavericks build (10.9.5) and there is no discernible pattern. Sometimes scripts fail and other times they don't. It does appear that restarting the server is triggering the bug - we've not seen scripts fail after working or work after failing without a server restart. We have seen several server stop/start combinations get it working again - but not always on the first try. For instance, 3 stop/start cycles of the server failed to get it working but after a 4th attempt it started working again.

The problem as we understand it appears to be a bug introduced in Lion (and exacerbated in Mavericks) where the OS gets confused when trying to target some applications from AppleScript. We do know that the problem is exacerbated by having multiple copies of the server installed (it rarely works in that case) but unfortunately it looks like subsequent releases of Mavericks (and likely Yosemite as well) have made the problem worse, not better.

Here's more specifics after we started meticulously documenting our testing: in our testing, it never took more than two server restarts to trigger the bug (scripts stopped working) and, in fact, it mostly only took a single restart. The good news is that we could always get it working again by stopping/starting the server. On average, it took 2.2 stop/start combinations to get it working and Mac reboots didn't appear to make any difference. The most stop/restart attempts we saw was 5. Of course, because we don't know/understand this bug more, your experience may be different.

So - bottom line: if you see this error first make sure you have no other copies of the IndigoServer.app on any mounted hard drive. This would likely be because you have previous versions still installed, so look in these locations:

/Library/Application Support/Perceptive Automation/Indigo 7/
/Library/Application Support/Perceptive Automation/Indigo 6/
/Library/Application Support/Perceptive Automation/Indigo 5/
/Library/Application Support/Perceptive Automation/Indigo 4/
/Library/Application Support/Perceptive Automation/Indigo 2/

Note: those are in the Library folder at the top-level of your hard drive, not the one in your home directory. In the Finder, select the Go->Go To Folder... menu item and paste in each one and it'll open a window to that folder. Just delete the IndigoServer.app file (not just move it to the trash, but also empty the trash so it's really deleted).

Once you've done that, if you're still seeing the issue just repeat these steps until it's working again:

  1. Select Indigo 7.2->Stop Server
  2. On the Server Connection Status dialog, click the Start Local Server... button
  3. On the Start Local Server dialog, click the Start Server button
  4. Once the server is up, run a test script that talks to the IndigoServer

Hopefully it will start working after only a couple of attempts.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Jan 06, 2015 5:51 pm
richo offline
Posts: 155
Joined: Nov 25, 2014
Location: Pomorskie, Poland

Re: AppleScript "Application isn't running" (-600) Errors

Is it possible to automatically discover that this error happens and run steps 1 to 4 in a script?

Ryszard

Posted on
Tue Jan 06, 2015 6:49 pm
jay (support) offline
Site Admin
User avatar
Posts: 15209
Joined: Mar 19, 2008
Location: Austin, Texas

Re: AppleScript "Application isn't running" (-600) Errors

Probably. It would require Unix shell scripting and lots of experimentation though (can't use AppleScript because, well, you're trying to detect when it's not working). Roughly (implementation specifics are up to you):

You could use the osascript command to test to see if an applescript can still target the server:

Code: Select all
/usr/bin/osascript -e 'tell application "IndigoServer" to log "test"'


That would return something like:

Code: Select all
35:45: execution error: IndigoServer got an error: Application isn’t running. (-600)


if the problem had been triggered. You could then grep the return string for "-600" and if you find it then kill the IndigoServer.app process. Then launchd would try to relaunch the server automatically and you could test again.

This is just a rough outline of steps that might work - we've never tried it before so you'll just have to experiment.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jan 07, 2015 5:23 pm
richo offline
Posts: 155
Joined: Nov 25, 2014
Location: Pomorskie, Poland

Re: AppleScript "Application isn't running" (-600) Errors

Ok will try it in free time


Sent using Tapatalk

Ryszard

Posted on
Fri Jan 30, 2015 12:17 pm
autolog offline
Posts: 2673
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT+0]

Re: AppleScript "Application isn't running" (-600) Errors

Is there any possibility that this incredibly annoying problem could be an Indigo startup timing problem - how things get registered with OS X for example: speed and order of threads starting up?

I ask this because I have been running some tests using the Script Editor in JavaScript rather than AppleScript mode. Entering the code:
Code: Select all
indigoApp = Application('com.perceptiveautomation.indigo-server')
indigoApp.log("log JavaScript Test")
is giving the result:
Code: Select all
app = Application("IndigoPluginHost")
   app.INDOLog ("log JavaScript Test")
      --> Error -1708: Message not understood.
Result:
Error -1708: Message not understood.
I was trying out JavaScript after singularly failing to get beyond the -600 AppleScript error :(

When it fails (90% of the time), it always fails with the same error - It seems to be trying to access IndigoPluginHost. If at the same time, I run the AppleScript test it is failing with the -600 error.

Note: I have also tested with accessing the Indigo server by:
Code: Select all
indigoApp = Application(<process id>)
indigoApp = Application('IndigoServer')
This testing has been done with every single plugin disabled. There are just three IndigoPluginHost processes running, namely:
/Library/Application Support/Perceptive Automation/Indigo 6/IndigoPluginHost.app/Contents/PlugIns/ScriptExecutor.indigoPlugin/
/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/.Action Collection.indigoPlugin/Contents/Server Plugin
/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/.Z-Wave.indigoPlugin/Contents/Server Plugin


When it works, I get the message in the Indigo Event Log and my AppleScript for SIRI works.

I just thought it was interesting that AppleScript and JavaScript were giving different errors - maybe the JavaScript error might shed some light on the problem?

At the moment AppleScript is too unreliable to use in a "production" environment which is a shame as I would really like to use SIRI from my iPhone. :)

Posted on
Fri Jan 30, 2015 7:09 pm
jay (support) offline
Site Admin
User avatar
Posts: 15209
Joined: Mar 19, 2008
Location: Austin, Texas

Re: AppleScript "Application isn't running" (-600) Errors

That's interesting, and might point to the OS bug that's causing the problem. The plugin host app definitely has a different ID (com.perceptiveautomation.indigo-plugin-host), so if the scripting engine is returning the wrong ID then that is definitely a problem.

However, the Indigo server always starts up before any plugin host process - because it's the process that launches those. So I don't think it's a timing issue.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Feb 02, 2015 10:45 am
matt (support) offline
Site Admin
User avatar
Posts: 18955
Joined: Jan 27, 2003
Location: Texas

Re: AppleScript "Application isn't running" (-600) Errors

Hi Jon,

As Jay mentioned, that is indeed very interesting that on bundle ID look-up it is returning the plugin-host target instead of the Indigo server target. I cannot imagine why or how that can be the case. The Info.plist for the plugin host definitely has unique CFBundleIdentifier, CFBundleSignature, and CFBundleName values. Both bundle IDs are, however, similar: com.perceptiveautomation.indigo-plugin-host versus com.perceptiveautomation.indigo-server.

I just double-checked and the hyphen character is supposed to be legal:

Dev Docs wrote:
The bundle ID string must be a uniform type identifier (UTI) that contains only alphanumeric (A-Z,a-z,0-9), hyphen (-), and period (.) characters.


Off the top of my head, I don't believe the bundle ID used by IPH is used internally by Indigo (it has no useful AppleScript API), so you could try hacking the file:

Code: Select all
/Library/Application Support/Perceptive Automation/Indigo 6/IndigoPluginHost.app/Contents/Info.plist

by changing this line:

Code: Select all
   <string>com.perceptiveautomation.hahahaindigo-plugin-host</string>

to:

Code: Select all
   <string>com.perceptiveautomation.maybethiswillavoidapplebug</string>

There might be some tricks involved to get Mac OS to rebuild its internal database of bundle IDs, so you might have to reboot and/or copy the modified version of the IndigoPluginHost app to an external volume (deleting the original version), then copy it back. If you try it then let us know how it goes...

Also I found some info online of similar problems in Firefox, where an AppleScript that targets the main FF process to quit is instead quitting one of the FF plugins. I suspect the problem therefore might be caused by applications like Indigo and FF, that start other processes (plugins in this case). Mac OS is then getting confused as to what process to target for a given bundle ID. I'm not sure how we can work around the bug if that is the case.

Image

Posted on
Mon Feb 02, 2015 1:13 pm
autolog offline
Posts: 2673
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT+0]

Re: AppleScript "Application isn't running" (-600) Errors

Hi Matt,
No luck I'm afraid -
  • shutdown Indigo
  • I changed the pluginHost (moved it to my mba),
  • rebooted the server,
  • shutdown the just started Indigo (which wasn't happy about the missing pluginhost :wink: ),
  • copied the pluginHost back and restarted Indigo.
Still got the error :(

I have been getting a mixture of -1708s and -600s.

As you say if FF is having the same sort of issue, it does look like Apple will need to sort it.

Maybe there is an alternate way to get a message into Indigo (maybe via a plugin)?
I'll have a bit more of a think about it :)

Posted on
Mon Feb 02, 2015 7:07 pm
jay (support) offline
Site Admin
User avatar
Posts: 15209
Joined: Mar 19, 2008
Location: Austin, Texas

Re: AppleScript "Application isn't running" (-600) Errors

autolog wrote:
Maybe there is an alternate way to get a message into Indigo (maybe via a plugin)?


Would the RESTful API work?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Feb 03, 2015 8:58 am
autolog offline
Posts: 2673
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT+0]

Re: AppleScript "Application isn't running" (-600) Errors

jay (support) wrote:
autolog wrote:
Maybe there is an alternate way to get a message into Indigo (maybe via a plugin)?


Would the RESTful API work?

Excellent suggestion :D

I think I have got it working but not without discovering another Apple bug :wink:

The AppleScript in Messages receives a message from SIRI and updates a variable in Indigo using the statement:
Code: Select all
set theResponse to do shell script "curl -X PUT -u <MY USERID>:<MY PASSWORD> --digest --data value='" & theMessage & "' http://127.0.0.1:8176/variables/iMessage"
where theMessage is the response from SIRI and iMessage is the name of the Indigo variable..

I have a test python script running that is triggered on the iMessage variable change. It stores the variable contents before setting the variable to a value indicating it has been processed i.e. 'ACTIONED:' followed by the contents of theMessage. Obviously this will fire the trigger again and so there is a condition to only pass the message on if it does not contain 'ACTIONED:'. Note: This is done so that issuing the same command twice (e.g toggling a lamp) will result in the second command being processed otherwise it would be ignored AFAIK.

The script then tries to make sense of the message and performs an appropriate Indigo command.

This is the next bit I need to look at: what is the best way to interpret the incoming message to make it as flexible as possible.

The Apple bug: It appears you can get an AppleScript timeout (script running for more than 10 seconds) as soon as the message is received. Patently ten seconds hasn't passed. It is probably another Yosemite bug and there are various work arounds suggested for it on the web. In summary, setting the Applescript in Messages to None and then back to the name of your script, quitting Messages and restarting it appears to fix it. I am probably tempting fate here :wink:

Thanks again for the suggestion Jay :)

Posted on
Tue Feb 03, 2015 5:06 pm
gregjsmith offline
Posts: 946
Joined: Apr 01, 2003
Location: Rio Rancho, NM

Re: AppleScript "Application isn't running" (-600) Errors

This has been quite an annoying problem for me since I installed Yosemite. I have several apps that talk to each other and none of them gives me this error except IndigoServer.

The reinstall application procedures worked a few times but stopped for some unknown reason. I went through and removed my time machine back up as that was showing multiple copies of IndigoServer but I was still getting the error.

I eventually found if I quit indigo server, used script editor and made a script that said

tell application "IndigoServer"
...Return a variable value , any variable it doesn't matter which one...
end tell

The script editor would launch indigo server and return the value and all other scripts would now run.

No errors now until this solution breaks.

Posted on
Tue Feb 03, 2015 8:14 pm
gregjsmith offline
Posts: 946
Joined: Apr 01, 2003
Location: Rio Rancho, NM

Re: AppleScript "Application isn't running" (-600) Errors

" Application isn’t running" started again and the script editor trick didn't work this time. I'm out of options and patients.

Posted on
Mon Feb 16, 2015 9:22 am
miked0809 offline
Posts: 8
Joined: May 16, 2014

Re: AppleScript "Application isn't running" (-600) Errors

I've come up with a kludgy workaround for this problem until we get a fix from Apple (or an official "workaround" from Indigo). In summary, I have set an AppleScript Handler in iMessages preferences which will write any incoming iMessages to a text file. In this applescript handler, there are no references to IndigoServer to cause the -600 error. I then created an Indigo schedule (currently set to run every minute) with an embedded Applescript which will check for any new output to the text file (i.e. basically manually polling for a new iMessage). If there is a new message written to the file, then the script will process it just like it did using the original iMessages applescript handler.

A few things to note:
  • you don't get an immediate response, which kind of sucks (i.e. it will take <= 1 minute, or however often you set your schedule to check for new messages)
  • not sure what kind of impact checking every minute will have on Indigo or my system
  • currently it would only be able to process one new message per minute (or whatever frequency I set the Indigo schedule to), so you can't send a bunch of rapid-fire iMessages to Indigo and expect it to be able to handle them in sequence.
  • I had to use an embedded applescript in my Indigo schedule to avoid the -600 error I was getting by referencing the script in a file
  • The incoming iMessage text is saved to a file called /Library/Application Support/Perceptive Automation/Indigo 6/Scripts/iMessage.txt

To use:
  • Copy/paste the Applescript handler code into a new applescript file and save it to the correct location (e.g. /Users/[username]/Library/Application Scripts/com.apple.iChat)
  • Take note of the lines in the Applescript Handler beginning with "TODO" - you'll need to supply your own values for these
  • Open iMessages and set your Applescript Handler to the new script
  • Create a new schedule in Indigo and set it to run every X minutes
  • Copy/paste the applescript code to an embedded action script in your schedule, modify the iMessage processing code in the --Main-- section to suit your environment
  • Create a new variable in Indigo called "iMessageContents"


Here is the iMessage AppleScript handler I am using:

Code: Select all
using terms from application "Messages"


-- TODO: Set this to your list of authorized users, should be the name(s) of someone in your Contacts (e.g. {"John Doe","Mary Smith"})
property authorizedUserList : {}

-- TODO: set this to the iMessage email of your admin (e.g. "email@icloud.com"), this is used to send iMessages back to when someone tries to access that is not authorized
property adminBuddy : ""

-- TODO: set this to the iMessage service id of your indigo account (e.g. "E:indigo@domain.com"), this is used to send iMessages back to when someone tries to access that is not authorized
property indigoMessageService : ""

property theSender : "local"

--
-- check if sender is authorized (checks authorizedUserList for authorized users)
--
on isAuthorized(theSender, theMessage)

   set authorized to "false"
   if authorizedUserList contains theSender then
      set authorized to "true"
   else
     -- send me a message warning me an authorized attempt was made
      sendMessagetoAdmin("Unauthorized user [" & theSender & "] tried to send the following Indigo command : " & theMessage)

      set authorized to "false"
   end if
   return authorized
end isAuthorized

--
-- Send an iMessage to an admin (e.g. use to report unauthorized use)
--
on sendMessagetoAdmin(theMessage)
   if adminBuddy is not equal to "" then
      if indigoMessageService is not equal to "" then
         tell application "Messages"
             set theBuddy to buddy adminBuddy of service indigoMessageService
             send theMessage to theBuddy
         end tell
      else
         display notification "Cannot send iMessage to Admin: indigoMessageService is not defined in Copy To File.applescript" sound name "default"
         delay 1
      end if
   end if
end sendMessagetoAdmin

-- write to file
on writeToFile(theMessage, targetFile)
   set retVal to "true"

   try
      set the targetFile to the targetFile as string
      set the openTargetFile to open for access file targetFile with write permission
      set eof of the openTargetFile to 0
      write theMessage to the openTargetFile starting at eof
      close access the openTargetFile
      return retVal
   on error
      set retVal to "error writing to targetFile"
      try
         close access file targetFile
      on error
         set retVal to "error closing targetFile"
      end try
      return retVal
   end try
end writeToFile

-- copy the incoming iMessage to a file
on copyToFile(theMessage)
   set retVal to "false"

   try
      set outputFile to (("Library:Application Support:Perceptive Automation:Indigo 6:Scripts:iMessage.txt") as string)
      set retVal to writeToFile(theMessage, outputFile)
   on error
      set retVal to "Error processing message " & theMessage
   end try
   return retVal
end copyToFile


-- When first message is received, accept the invitation and send a greeting message from Indigo.
on received text invitation theMessage from theBuddy for theChat
   set theSender to (full name of theBuddy) as text
   accept theChat

   if isAuthorized(theSender, theMessage) is "true" then
      send "Welcome to Indigo Remote Control. " & copyToFile("help") to theChat
   else
      send "I'm sorry, but you are not authorized to send me messages." to theChat
   end if
end received text invitation


-- On subsequent messages, pass the message directly to Indigo Remote Control.
on message received theMessage from theBuddy for theChat
   set theSender to (full name of theBuddy) as text

   if isAuthorized(theSender, theMessage) is "true" then
      if copyToFile(theMessage) is "true" then
         set theResponse to "I will send your command to Indigo"
      else
         set theResponse to "Something went wrong, try your command again."
      end if
   else
      set theResponse to "I'm sorry, but you are not authorized send me messages."
   end if

   -- send back the response.
   send theResponse to theChat

end message received

--locally test commands
display dialog "Send me a message:" default answer "status"
set theMessage to the text returned of the result
set theResponse to copyToFile(theMessage)
try
   log "theResponse = " & theResponse
on error
   log "theResponse = undefined"
end try
display dialog theResponse

# The following are unused but need to be defined to avoid an error
on received audio invitation theText from theBuddy for theChat
end received audio invitation

on received video invitation theText from theBuddy for theChat
end received video invitation

on received remote screen sharing invitation from theBuddy for theChat
end received remote screen sharing invitation

on received local screen sharing invitation from theBuddy for theChat
end received local screen sharing invitation

on received file transfer invitation theFileTransfer
end received file transfer invitation

on buddy authorization requested theRequest

end buddy authorization requested

on message sent theMessage for theChat
end message sent

on chat room message received theMessage from theBuddy for theChat

end chat room message received

on active chat message received theMessage

end active chat message received

on addressed chat room message received theMessage from theBuddy for theChat

end addressed chat room message received

on addressed message received theMessage from theBuddy for theChat

end addressed message received

on av chat started

end av chat started

on av chat ended

end av chat ended

on login finished for theService

end login finished

on logout finished for theService

end logout finished

on buddy became available theBuddy

end buddy became available

on buddy became unavailable theBuddy

end buddy became unavailable

on completed file transfer

end completed file transfer

end using terms from


And here is the embedded Applescript I am using in my scheduled task to process any new iMessage text that is written to my file:

Code: Select all
property filePath : "/Library/Application Support/Perceptive Automation/Indigo 6/Scripts/iMessage.txt"
property debugFlag : "false"

--
-- read in the file and return the contents as a string
--
on readFile()
   set inputFile to filePath as text
   
   -- read in file to variable
   open for access inputFile
   
   --set fileContents to (read inputFile)
   set fileContents to do shell script "cat " & quoted form of inputFile
   
   close access inputFile
   
   return fileContents
end readFile

--
-- delete the file when we're done
--
on deleteFile()
   try
      do shell script "rm '" & filePath & "'"
   end try
end deleteFile

--
-- clean up when done
--
on cleanup()
   debugMsg("cleaning up")
   
   -- reset iMessageContents variable   
   setIndigoVariable("iMessageContents", "")
   
   -- delete the file when we're done so it doesn't get reprocessed
   deleteFile()
end cleanup


--
-- replaces 'search_string' in 'this_text' with 'replacement_string' 
--
on replace_chars(this_text, search_string, replacement_string)
   set AppleScript's text item delimiters to the search_string
   set the item_list to every text item of this_text
   set AppleScript's text item delimiters to the replacement_string
   set this_text to the item_list as string
   set AppleScript's text item delimiters to ""
   return this_text
end replace_chars

on CapitalizeFirstLetter_ofEveryWord(InputString)
   set TheString to do shell script "echo " & InputString & " | tr '[A-Z]' '[a-z]'"
   set wordsofTheString to words of TheString as list
   set TotalCount to count of wordsofTheString
   set theCount to 1
   repeat until theCount is greater than TotalCount
      set theWord to item theCount of wordsofTheString
      set theChars to characters of theWord as list
      set Capital to item 1 of theChars
      set item 1 of theChars to do shell script "echo " & Capital & " | tr '[a-z]' '[A-Z]'"
      if theCount is less than TotalCount then
         set theWord to (theChars as string) & " "
      else
         set theWord to (theChars as string)
      end if
      set item theCount of wordsofTheString to theWord
      set theCount to theCount + 1
   end repeat
   set TheString to wordsofTheString as string
   return TheString
end CapitalizeFirstLetter_ofEveryWord

on trim_line(this_text, trim_chars, trim_indicator)
   -- 0 = beginning, 1 = end, 2 = both
   set x to the length of the trim_chars
   -- TRIM BEGINNING
   if the trim_indicator is in {0, 2} then
      repeat while this_text begins with the trim_chars
         try
            set this_text to characters (x + 1) thru -1 of this_text as string
         on error
            -- the text contains nothing but the trim characters
            return ""
         end try
      end repeat
   end if
   -- TRIM ENDING
   if the trim_indicator is in {1, 2} then
      repeat while this_text ends with the trim_chars
         try
            set this_text to characters 1 thru -(x + 1) of this_text as string
         on error
            -- the text contains nothing but the trim characters
            return ""
         end try
      end repeat
   end if
   return this_text
end trim_line

--
-- returns the value of passed in variable name
--
on getIndigoVariable(IndigoVariable)
   tell application "IndigoServer"
      set theVariableValue to get value of variable IndigoVariable
   end tell
   return theVariableValue
end getIndigoVariable

--
-- sets the value of the passed in variable name
--
on setIndigoVariable(IndigoVariable, VariableValue)
   tell application "IndigoServer"
      set value of variable IndigoVariable to VariableValue
      set theVariableValue to get value of variable IndigoVariable
   end tell
   return "Variable set to " & theVariableValue
end setIndigoVariable

--
-- executes a named indigo action
--
on executeIndigoAction(IndigoAction)
   tell application "IndigoServer"
      execute group IndigoAction
   end tell
   return "Action: " & IndigoAction & " Executed"
end executeIndigoAction

--
-- turns on a named indigo device
--
on turnonIndigoDevice(IndigoDevice)
   try
      tell application "IndigoServer"
         turn on IndigoDevice
      end tell
      return IndigoDevice & " was told to turn on"
      
   on error
      logError("error turning on " & IndigoDevice)
   end try
end turnonIndigoDevice

--
-- turns off a named indigo device
--
on turnoffIndigoDevice(IndigoDevice)
   try
      tell application "IndigoServer"
         turn off IndigoDevice
      end tell
      return IndigoDevice & " was told to turn off"
   on error
      logError("error turning off " & IndigoDevice)
   end try
end turnoffIndigoDevice

on debugMsg(debugMsg)
   if debugFlag is "true" then
      tell application "IndigoServer"
         log "DEBUG: " & debugMsg using type "Indigo Control Script"
      end tell
   end if
end debugMsg

on logMsg(logMsg)
   tell application "IndigoServer"
      log logMsg using type "Indigo Control Script"
   end tell
end logMsg

on logError(errorMsg)
   set errorMsg to "ERROR: " & errorMsg
   tell application "IndigoServer"
      log errorMsg using type "Indigo Control Script"
   end tell
end logError

----------------------------------------------------------------------------------------
-- Main
----------------------------------------------------------------------------------------
debugMsg("--- Running iMessageControl script ---")

set theMessage to readFile()

debugMsg("file contents: " & theMessage)

setIndigoVariable("iMessageContents", theMessage)

if theMessage is equal to "" then
   debugMsg("Exiting script, no new message")
   return
end if

-- use default "unknown" command, just in case.
set theResponse to "Unknown command."
set theMessage to trim_line(theMessage, "to ", 0)

if theMessage does not contain "say" then
   set theMessage to replace_chars(theMessage, "the ", "")
end if
set theMessage to replace_chars(theMessage, "'", "")

set theSpokenResponse to "unknown"

try
   logMsg("iMessage received: " & theMessage)
   
   if theMessage contains "status" then
      set theResponse to "Alive and Well!"
   else if theMessage starts with "turn on" then
      set targetDevice to CapitalizeFirstLetter_ofEveryWord(trim_line(theMessage, "turn on ", 0))
      set theResponse to turnonIndigoDevice(targetDevice)
   else if theMessage starts with "turn off" then
      set targetDevice to CapitalizeFirstLetter_ofEveryWord(trim_line(theMessage, "turn off ", 0))
      set theResponse to turnoffIndigoDevice(targetDevice)
   else if theMessage starts with "start" then
      set targetDevice to CapitalizeFirstLetter_ofEveryWord(trim_line(theMessage, "start ", 0))
      set theResponse to turnonIndigoDevice(targetDevice)
   else if theMessage starts with "stop" then
      set targetDevice to CapitalizeFirstLetter_ofEveryWord(trim_line(theMessage, "stop ", 0))
      set theResponse to turnoffIndigoDevice(targetDevice)
   else if theMessage starts with "execute" then
      set targetAction to trim_line(theMessage, "execute ", 0)
      set targetAction to trim_line(targetAction, "action ", 0)
      set targetAction to trim_line(targetAction, "group ", 0)
      set targetAction to CapitalizeFirstLetter_ofEveryWord(targetAction)
      set theResponse to executeIndigoAction(targetAction)
      
   else if theMessage contains "nest home" then
      set theResponse to executeIndigoAction("Nest - Set Home")
      
   else if theMessage contains "nest away" then
      set theResponse to executeIndigoAction("Nest - Set Away")
   else if theMessage contains "check garage" or theMessage contains "garage door open" or theMessage contains "garage door is open" then
      set isGarageDoorOpen to getIndigoVariable("isGarageDoorOpen")
      if isGarageDoorOpen is "true" then
         set theResponse to "Garage Door is OPEN"
      else
         set theResponse to "Garage Door is CLOSED"
      end if
      
   else if theMessage contains "roomba clean" or theMessage contains "roomba run" or theMessage contains "roomba cleaned" then
      set wasRoombaRunToday to getIndigoVariable("wasRoombaRunToday")
      
      if wasRoombaRunToday is "true" then
         set theResponse to "Yes, Roomba cleaned today"
      else
         set theResponse to "No, Roomba did not clean today"
      end if
      
   else if theMessage contains "dont run roomba" or theMessage contains "not run roomba" then
      setIndigoVariable("wasRoombaRunToday", "true")
      set wasRoombaRunToday to getIndigoVariable("wasRoombaRunToday")
      if wasRoombaRunToday is "true" then
         set theResponse to "OK, Roomba will not clean today"
      else
         set theResponse to "Something went wrong, Roomba may still clean today"
      end if
      
   else if theMessage contains "outside music" then
      -- get Denon receiver ready for music outside
      set theResponse to executeIndigoAction("Denon - Get Zone 2 Ready")
      set theResponse to theResponse & ". You can now play music to Airport Great Room."
      
   else if theMessage contains "disable" and theMessage contains "refrigerator" then
      set theResponse to executeIndigoAction("Leak - Disable Leak Alert for Refrigerator")
      
   else if theMessage contains "disable" and theMessage contains "water" then
      set theResponse to executeIndigoAction("Leak - Disable Leak Alert for Hot Water Tank")
      
   else if theMessage contains "disable" and theMessage contains "dishwasher" then
      set theResponse to executeIndigoAction("Leak - Disable Leak Alert for Dishwasher")
      
   else if theMessage contains "disable" and theMessage contains "wash" then
      set theResponse to executeIndigoAction("Leak - Disable Leak Alert for Washing Machine")
      
   else
      -- display available commands on "help"
      set theResponse to "status | devices | turn on <device> | turn off <device> | execute action <action> | check garage | did Roomba clean today | don't run roomba today | outside music | disable <leak sensor>"
      
      if theMessage is not "help" then
         set theResponse to "*Unknown command* Available commands are: " & theResponse
      end if
      
      set theSpokenResponse to "dontSpeak"
   end if
   
   logMsg("Indigo Response: " & theResponse)
   
   -- speak the response
   set speakResponses to getIndigoVariable("speakSMSResponses")
   if speakResponses is "true" then
      if theSpokenResponse is not "dontSpeak" then
         if theSpokenResponse is "unknown" then
            set theSpokenResponse to theResponse
         end if
         debugMsg("theSpokenResponse = " & theSpokenResponse)
         say theSpokenResponse
      end if
   end if
   
on error
   logError("Error processing message " & theMessage)
end try

cleanup()


Posted on
Mon Feb 16, 2015 9:42 am
gregjsmith offline
Posts: 946
Joined: Apr 01, 2003
Location: Rio Rancho, NM

Re: AppleScript "Application isn't running" (-600) Errors

I am reading and writing to a plist file.

This code is executed when a single variable changes via a trigger event, since I don't have to "tell indigo" anything. The difficult part is every variable I need to share with outside apps needs to have a trigger event but at least I can copy and paste this same code for every one.

Code: Select all
try
   set theOutputFolder to path to documents folder as string
   set thePListPath to theOutputFolder & "Variables.plist"
   tell application "Finder"
      
      if not (exists file thePListPath) then
         set theEmptyPListData to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict/>
</plist>"
         set thePListFile to open for access thePListPath with write permission
         set eof of thePListFile to 0
         write theEmptyPListData to thePListFile starting at eof
         close access thePListFile
         tell application "System Events"
            tell property list file thePListPath
               tell contents to set value to {thevar1:""} & {thevar2:""} & {tehvar3:""}
            end tell
         end tell
      end if
   end tell
   
   set thevar1 to value of variable "thevar1"
   set thevar2  to value of variable "tehvar2"
   set thevar3  to value of variable "thevar3"
   
   tell application "System Events"
      tell property list file thePListPath
         tell contents to set value of property list item "thevar1" to thevar1  as string
         tell contents to set value of property list item "thevar2" to thevar2  as string
         tell contents to set value of property list item "thevar3" to thevar3  as string
      end tell
   end tell
on error TheError
   log "There was an error " & TheError
end try


This is how I read the plist. In this case I am using hazel to "passes applescript". I also have indigo read the contents of this plist and update variables but since it doesn't know when the values change I have it check it on a periodic basis.

Code: Select all
set theOutputFolder to path to documents folder as string
set thePListPath to theOutputFolder & "Variables.plist"

tell application "System Events"
   tell property list file thePListPath
      tell contents
         set TheValue to value of property list item "thevar1"
      end tell
   end tell
end tell

if TheValue is "true" then
   return true
else
   return false
end if

Posted on
Wed Feb 25, 2015 9:37 am
davinci offline
Posts: 249
Joined: Feb 14, 2015

Re: AppleScript "Application isn't running" (-600) Errors

Is this problem also happening for other Apps or only IndigoServer?

Btw. I'm sure Apple would help a developer.

Who is online

Users browsing this forum: No registered users and 2 guests