Applescript Conversion to Python

Posted on
Tue Apr 27, 2021 2:26 pm
ckeyes888 offline
Posts: 2276
Joined: Nov 26, 2009
Location: Kalispell, MT

Applescript Conversion to Python

Hey,

Lil help converting this:
Code: Select all
set value of variable "wsTemp_Out" to (value of variable "wsTemp_Out" as integer)

to python?

Thanks,

Carl

Posted on
Tue Apr 27, 2021 9:07 pm
whmoorejr offline
User avatar
Posts: 522
Joined: Jan 15, 2013
Location: Houston, TX

Re: Applescript Conversion to Python

ckeyes888 wrote:
Code: Select all
set value of variable "wsTemp_Out" to (value of variable "wsTemp_Out" as integer)


I think....

Code: Select all
wsTempOut = indigo.variables[123456]

# Getting the integer value
intValue = wsTempOut.getValue(int)   # 0 if it can't be converted
intValue = wsTempOut.getValue(int, default=10) # 10 if it can't be converted

indigo.variable.updateValue(123456, value=intValue)


However, I think a variable is always a string. You can convert it to a integer to use somewhere else in a phthon code, but I don't think you can save it back as an indigo variable that way.... but not sure.

Also... take a look at this... It goes into way more detail... https://wiki.indigodomo.com/doku.php?id=indigo_5_documentation:variable_class

Bill
My Plugin: My People

Posted on
Wed Apr 28, 2021 7:15 am
ckeyes888 offline
Posts: 2276
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Applescript Conversion to Python

That script returns: "Python argument types in"

I'll have a look at your link.

Thanks,

Carl

Posted on
Wed Apr 28, 2021 10:26 am
jay (support) offline
Site Admin
User avatar
Posts: 16767
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Applescript Conversion to Python

whmoorejr wrote:
However, I think a variable is always a string. You can convert it to a integer to use somewhere else in a phthon code, but I don't think you can save it back as an indigo variable that way.... but not sure.


You need to cast it to a string when setting the value:

Code: Select all
indigo.variable.updateValue(123456, value=str(intValue))

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Apr 28, 2021 10:27 am
jay (support) offline
Site Admin
User avatar
Posts: 16767
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Applescript Conversion to Python

ckeyes888 wrote:
Hey,

Lil help converting this:
Code: Select all
set value of variable "wsTemp_Out" to (value of variable "wsTemp_Out" as integer)

to python?


What are you trying to do with this script? It doesn't appear to do anything because variable values are always strings. So, basically, you're just setting it to exactly what it was (unless it wasn't something that can be converted to an integer in which case the script will fail).

[EDIT] - ok, so maybe if something else sets it and it's a float value, then this AppleScript would convert it to an integer. If that's the case, then the posted script (with the string cast) would work.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Jun 07, 2021 1:19 pm
rszmetro offline
Posts: 101
Joined: Sep 10, 2009
Location: East Hills, NY

Re: Applescript Conversion to Python

Hi,

I'm upgrading from 7.1 to the latest version and need to convert Applescripts to Python scripts. I've never done this before and an example would help me understand. Hers is an AppleScript I need to convert.
----------
-- Update Upstairs Temperature

tell application "IndigoServer"
set myThermoDev to device "Thermostat - A/C"
set tempList to temperatures of myThermoDev
set TempUpStairs to first item of tempList as real
set value of variable "tempUpstairs" to first item of tempList as real
end tell
----------

Thanks!
Rob Z

Rob Z

Posted on
Mon Jun 07, 2021 2:14 pm
FlyingDiver offline
User avatar
Posts: 5305
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Applescript Conversion to Python

rszmetro wrote:
Hi,

I'm upgrading from 7.1 to the latest version and need to convert Applescripts to Python scripts. I've never done this before and an example would help me understand. Hers is an AppleScript I need to convert.
----------
-- Update Upstairs Temperature

tell application "IndigoServer"
set myThermoDev to device "Thermostat - A/C"
set tempList to temperatures of myThermoDev
set TempUpStairs to first item of tempList as real
set value of variable "tempUpstairs" to first item of tempList as real
end tell
----------

Thanks!
Rob Z


Where are you running this script? Inside Indigo? If so, is there some reason you can't use the built-in Indigo action to copy the temperature from the device to a variable?

And what's the point of set TempUpStairs to first item of tempList as real? You never use the variable you just set.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest