Applescript Bug?

Posted on
Thu Sep 03, 2009 3:53 pm
hunterford offline
Posts: 10
Joined: Jun 01, 2008

Applescript Bug?

Not sure if this actually a bug or if I'm just doing something wrong, but hopefully someone will be able to duplicate it or tell me what I'm doing wrong. Here it goes:

For demonstration purposes, I'm gonna use iTunes as an example. Sorry for the lengthy code, but I just added a few lines so that the variable is created for you in Indigo for easier debugging.

Code: Select all
tell application "iTunes"
   set iTunesPlaylistRepeat to song repeat of current playlist as string
end tell

tell application "IndigoServer"
   if not (variable "iTunesPlaylistRepeat" exists) then
      make new variable with properties {name:"iTunesPlaylistRepeat", value:iTunesPlaylistRepeat}
   else
      if value of variable "iTunesPlaylistRepeat" is not iTunesPlaylistRepeat then
         set value of variable "iTunesPlaylistRepeat" to iTunesPlaylistRepeat
      end if
   end if
end tell


Now when I run this in AppleScript Editor (I'm on Snow Leopard), it creates/updates the variable just fine in Indigo with the value "all". However if Indigo executes this script, it fills it in with "«constant ****kAll»". Obviously it's the constant and not the string value. Any ideas as to why?

I'm running the latest beta of Indigo.

Thanks!

Posted on
Thu Sep 03, 2009 4:42 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Applescript Bug?

hunterford wrote:
Not sure if this actually a bug or if I'm just doing something wrong, but hopefully someone will be able to duplicate it or tell me what I'm doing wrong. Here it goes:

For demonstration purposes, I'm gonna use iTunes as an example. Sorry for the lengthy code, but I just added a few lines so that the variable is created for you in Indigo for easier debugging.

Code: Select all
tell application "iTunes"
   set iTunesPlaylistRepeat to song repeat of current playlist as string
end tell

tell application "IndigoServer"
   if not (variable "iTunesPlaylistRepeat" exists) then
      make new variable with properties {name:"iTunesPlaylistRepeat", value:iTunesPlaylistRepeat}
   else
      if value of variable "iTunesPlaylistRepeat" is not iTunesPlaylistRepeat then
         set value of variable "iTunesPlaylistRepeat" to iTunesPlaylistRepeat
      end if
   end if
end tell


Now when I run this in AppleScript Editor (I'm on Snow Leopard), it creates/updates the variable just fine in Indigo with the value "all". However if Indigo executes this script, it fills it in with "«constant ****kAll»". Obviously it's the constant and not the string value. Any ideas as to why?

I'm running the latest beta of Indigo.

Thanks!


I just tried it on Snow Leopard and didn't see the problem - it worked fine for me as long as I had an actual track selected (see my notes below). However, you might try enclosing the string coercion in parens:

Code: Select all
set iTunesPlaylistRepeat to (song repeat of current playlist as string)


to force coercion - coercions are one of the things that got changed pretty dramatically in Snow Leopard so you may be seeing this.

Note: talking to iTunes from an embedded script in Indigo is a bit dangerous without putting it in a try block. iTunes, for various reasons, will sometimes not reply to AppleScripts, and because scripts (at least until Snow Leopard) had to be run in the application's main thread, you may hang up your Indigo server. Another caution: if whatever is selected in iTunes isn't an actual track (like, say, if you just synced your iPod and it's selected) your script is going to get an error...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Sep 03, 2009 6:21 pm
hunterford offline
Posts: 10
Joined: Jun 01, 2008

(No subject)

Thanks for the response Jay!

Unfortunately, that didn't fix it for me. :cry:

The first thing I did was to try the parenthetical coercion.

I did a test though, and I think maybe I can isolate the problem more specifically.

As an embedded Applescript, the code works fine. And it also works fine in AppleScript Editor. The only time it doesn't work is if I save it as a scpt file and have it run inside Indigo as a file. Maybe you can confirm this?

Thanks for the notes. Following the notes on the wiki, I actually have all my code in "try" and "with timeout" blocks. Just to keep things brief for my post, I decided to not include that.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests