Help - can't get shell script to execute

Posted on
Fri Jul 19, 2013 2:27 pm
gmusser offline
Posts: 290
Joined: Feb 12, 2005
Location: New Jersey

Help - can't get shell script to execute

In an AppleScript, I have a line like the following:

Code: Select all
do shell script "curl -m 5 --request PUT --data 96.0 --header \"X-ApiKey:<key>\" https://api.xively.com/v2/feeds/97114/datastreams/1.csv


When I execute the curl command in a Terminal window, it works perfectly: the datum is uploaded to Xively/Cosm. But it doesn't work from an AppleScript within Indigo. I've tried putting it both inside and outside a tell block. It worked as recently as last January, so perhaps I need to do something differently in more recent versions of Indigo.

I'm running the latest beta of 6.

George

Posted on
Fri Jul 19, 2013 3:25 pm
wiery offline
Posts: 288
Joined: Jun 02, 2008
Location: Ireland

Re: Help - can't get shell script to execute

you have mismatched ", there are three in what you pasted

Posted on
Fri Jul 19, 2013 4:09 pm
gmusser offline
Posts: 290
Joined: Feb 12, 2005
Location: New Jersey

Re: Help - can't get shell script to execute

Oops, I cut-and-pasted incorrectly. They're matched properly in the script.

Posted on
Fri Jul 19, 2013 4:57 pm
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Help - can't get shell script to execute

Use the full path to curl (/usr/bin/curl)- when AppleScript runs shell commands it doesn't inherit the normal shell variables like paths.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jul 19, 2013 7:33 pm
gmusser offline
Posts: 290
Joined: Feb 12, 2005
Location: New Jersey

Re: Help - can't get shell script to execute

Ah, found the trouble: with Xively, you need to use the "--insecure" flag for curl.

Posted on
Sat Jul 20, 2013 12:41 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Help - can't get shell script to execute

I found the following code works well with cosm (xively):

Code: Select all
set myPachubeAPIKey to "<put your code here>"
set myPachubeFeed to "http://www.pachube.com/api/feeds/<put your feed here>.csv"

tell application "IndigoServer"
   set poolAirHumidity to value of variable "poolAirHumidity"
   set poolAirTemp to value of variable "poolAirTemp"
   set poolPumpCurrentDraw to value of variable "poolPumpCurrentDraw"
   set poolWaterTemp to value of variable "poolWaterTemp"
   set outdoorLightLevel to value of variable "outdoorLightLevel"
end tell

set myData to poolAirHumidity & "," & poolAirTemp & "," & poolPumpCurrentDraw & "," & poolWaterTemp & "," & outdoorLightLevel

set myPachubeData to outdoorLightLevel & "," & poolAirHumidity & "," & poolAirTemp & "," & poolPumpCurrentDraw & "," & poolWaterTemp
try
   set CommandString to "curl -m 120 -S --request PUT -H \"X-PachubeApiKey: " & myPachubeAPIKey & "\" " & "--data " & myPachubeData & " " & "\"" & myPachubeFeed & "\""
   set myRes to do shell script CommandString
   
   if myRes is not equal to " " then
      log "Problem with posting to pachube. curl result is:" & myRes
   end if
on error
   log "Error execting curl to post to pachube.com: Result was " & myRes
end try

Posted on
Sun Nov 03, 2013 10:43 am
arwatson2000 offline
Posts: 34
Joined: Oct 17, 2011

Re: Help - can't get shell script to execute

I just spent a day working on this and (for me at least) it was confusing.

In short, I was able to use zwaze temperature, to Indigo, to Xively to graph using applescript exported as an app and then using LaunchD to drive this. For LaunchD control I used Lingon3 vs "LaunchD". Lingon was lower rated on the app store but MUCH easier to use. The process of creating a recurrent temp feed script execution of applescript was complicated, but perhaps I was missing something.

If people think a full verbose log of how I did this is beneficial let me know.

- andrew

Posted on
Sun Nov 03, 2013 11:57 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: Help - can't get shell script to execute

you don't need to use launched, setup a schedule or action or trigger

pick your time, condition when to run, repetition etc

go to action window
- select server actions / script and file actions / execute script
then
- click on choose, pick the applescript.SCPTt file you like to run

DO NOT chose EMBEDDED script, that has time limitations-and INDIGO will wait for the script to end, no other INDIGO action will occur


You could also put the wait / delay etc into the applescript.APP
Code: Select all
on run
   --- initialize variables and send to idle
   global myparameter
      set physicalSensors to"xxxxx"
   idle 2  -- run the "idle" program in 2 seconds
end run

-- enable quit
on quit
   continue quit
end quit



on idle -- this is the program that will be executed every xxx seconds as you set the "idle" time with    return xxx
       global myparameter  -- set once in on run
   
-- do your stuff here

  if xx > yy then
       return 500  -- this will run "idle" in 500 seconds again
  end

-- code
   if zz > 11
        quit  -- this will end it all
   end

end   
   


hope that helps

Karl

Posted on
Sun Nov 03, 2013 1:29 pm
arwatson2000 offline
Posts: 34
Joined: Oct 17, 2011

Re: Help - can't get shell script to execute

Very helpful; working with Launchd and Lingon was concerning.

thank you!

Posted on
Sun Nov 03, 2013 4:23 pm
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: Help - can't get shell script to execute

also when you don't want to have the applescript icon on the launch bar while it is running you can change the info.plist file:


1. in applescript:
after you export to .APP
choose stay open after lunch option


2. in finder:
right click on yourapplescript.APP
show contents
… go to info.plist
open info.plist with plain text editor
add the two lines indicated with <++++ as first entry after <dict> (naturally without the <+++++)

then the icon does not show up on the launch bar while the script is executing / idling.

When you screw up the file, don't worry, just create it again (in applescript editor export to app,….)

Karl

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>NSUIElement</key>    <+++++ add this
   <true/>                                 <++++++ add this
   <key>CFBundleAllowMixedLocalizations</key>
   <true/>
   <key>CFBundleDevelopmentRegion</key>
….

Posted on
Fri Nov 08, 2013 8:39 pm
arwatson2000 offline
Posts: 34
Joined: Oct 17, 2011

Re: Help - can't get shell script to execute

Great information, is there a way to log this in a database ? I cannot find a clear path about the SQL plugin. Thanks for the help.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests