script debugging (was Re: Barix aftermath, set unit property problem)

James Sentman james at sentman.com
Thu Jun 11 13:38:54 EDT 2015


LOTS of things changed between 854 and 877, all related to the fact that the app is a Cocoa app now and subject to all the new cruelness as far as apple events and scripts. That SHOULDN’t change anything in how any app interacts with it at all, and didn’t in any of my testing but I haven’t done anything like that.

I would first verify that the script runs at all. You can add another -e ‘write log \””test running\””’ to the command line and if that shoes up in XTension then at least you know for sure that the script is running.

There was a problem on earlier OS versions where background launched apps were not allowed to send apple events to the user space at all. I do not know if this is still the case or if there is a new sandbox for cocoa apps or what, but first verify that the script is actually running and is able to communicate with XTension by adding that line.

I would also experiment with adding a return to the end of the script, I know this is not technically necessary as applescript SHOULD return the latest variable that you used but you could experiment with -e ‘return myValue’ before the end tell too. 

Let me know what happens with that.


> On Jun 11, 2015, at 1:12 AM, ard jonker <ard.jonker at xs4all.nl> wrote:
> 
> James, did something fundamentally change between pre-854 and 877 regarding AppleScript calls from other applications?
> I've got this php interface that uses an applescript shell-exec to retrieve unit values.
> 	function readXtensionUnitValue($unitName="aatestunit"){
> 		$cmd="osascript -e 'tell application \"XTension\"' -e 'set MyValue to value of \"".$unitName."\"' -e 'end tell'";
> 		$appleScriptResponse=shell_exec($cmd);
> 		$ASRLength=strlen($appleScriptResponse)-1;
> 		$value=substr($appleScriptResponse,0,$ASRLength);
> 		return $value;
> 	}
> 	$unitName ="TCBoilerTop";
> 	echo "$unit value: ".readXtensionUnitValue($unitName)."\n";
> 
> When run stand-alone (ie. in a web page in the browser), I get a proper answer:
> 
> TCBoilerTop value: 45.0
> 
> When I run that as part of a LaunchDaemon, 
> 
> #sh
> 	/Applications/MAMP/bin/php5/bin/php -q /Applications/MAMP/htdocs/php/lib/hadatacollect.php 
> 
> since upgrading to 877, I no longer get any response. An empty string is returned. Up to last week, 'it just worked'.

Thanks,
 	James


James Sentman                       http://sentman.com		http://MacHomeAutomation.com





More information about the XTensionList mailing list