need help with applescript

Posted on
Mon Oct 15, 2012 1:02 pm
henkjanvries offline
User avatar
Posts: 108
Joined: May 05, 2012

need help with applescript

Hello

ive got an applescript which is used to get the program info from eyetv. What i want is just the short description. which is put into a variable in indigo. But i cant get just that part when i run the script.

perhaps someone can help me on my way on how to just extract one part of a outputted list in applescript.

Code: Select all
tell application "eyetv"
   if playing then
      get program info of player_window playing
   end if
end tell


output is this:

{currentShow:{startTime:date "Monday, October 15, 2012 5:05:00 PM", endTime:date "Monday, October 15, 2012 5:35:00 PM", title:"The king of Queens", shortDescription:"Amerikaanse comedyserie met Kevin James, Leah Remini, Jerry Stiller en anderen. De perikelen van Doug Heffernan, zijn vrouw Carrie en zijn schoonvader. Afl.: Bun dummy. "}, nextShow:{startTime:date "Monday, October 15, 2012 5:35:00 PM", endTime:date "Monday, October 15, 2012 6:05:00 PM", title:"Unhappily ever after", shortDescription:"Amerikaanse comedyserie met Geoff Pierson, Kevin Connolly, Nikki Cox en anderen. Afl.: Teacher's pet. Tiffany en Ryan ontvangen de resultaten van hun beroepskeuzetest. Tiffany is teleurgesteld met haar uitkomst; "}}

what i want is the 'shortdescription' part.

i hope someone has a clue for me, the internet has not been nice last week in helping me to find how to do this.

HenkJan

Posted on
Mon Oct 15, 2012 2:23 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: need help with applescript

I think this should work - it'll put the shortDescription string into the variable currentShortDescription:

Code: Select all
set currentShortDescription to ""
tell application "eyetv"
   if playing then
      set programInfo to program info of player_window playing
      set currentShortDescription to shortDescription of currentShow of programInfo
   end if
end tell

# the AppleScript variable currentShortDescription will now have the short description
# in it if the eyetv player is playing or nothing if not

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Oct 15, 2012 2:44 pm
henkjanvries offline
User avatar
Posts: 108
Joined: May 05, 2012

Re: need help with applescript

Thanks a million that worked! Could you explain what you did i can read it but i dont really follow. Why the extra set and why the long string of 'of' for shortdescription. This is the part where i just can't find the right explanation online

Posted on
Mon Oct 15, 2012 2:49 pm
henkjanvries offline
User avatar
Posts: 108
Joined: May 05, 2012

Re: need help with applescript

Btw how much info/characters can there be put in an indigo variable? Because i want to outpt the shortdescription into indigotouch pages. But that should he read from indigo variables

Posted on
Mon Oct 15, 2012 4:51 pm
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: need help with applescript

henkjanvries wrote:
Thanks a million that worked! Could you explain what you did i can read it but i dont really follow. Why the extra set and why the long string of 'of' for shortdescription. This is the part where i just can't find the right explanation online

Though I haven't done much scripting of EyeTV, I can probably address some of your question.

With AppleScript, curly braces { } represent a set of object "properties." A property can contain sets of other objects with their own properties. The AppleScript Jay wrote accesses a specific object's property within another object's property, within the currently playing window. Think of the "player_window" as one big container. It contains another, not quite so large "program info" container. The "program info" container holds the smaller "currentShow" and "nextShow" containers. Both of those smaller containers hold individual bits of information like "startTime", "endTime", "title", and "shortDescription." To tell AppleScript that you want to fill the variable "currentShowDescription" with the information found in the "shortDescription", which can be found in the "currentShow" container, which is in the "program info" container, in the larger "player_window" container, you say
Code: Select all
set currentShortDescription to shortDescription of currentShow of program info of player_window playing

Jay shortened "program info of player_window playing" by assigning those contents to the AppleScript variable "programInfo", resulting in
Code: Select all
set currentShortDescription to shortDescription of currentShow of programInfo

Posted on
Mon Oct 15, 2012 8:03 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: need help with applescript

There is no technical limit to the amount of data that can go into an Indigo variable, but in practice you probably don't want to add more than say a couple hundred characters. More may work but we've never really tested the upper end.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Oct 16, 2012 12:31 pm
henkjanvries offline
User avatar
Posts: 108
Joined: May 05, 2012

Re: need help with applescript

thanks it worked and the variables are being filled. my only question that remains, is this:

when i use your script, while trying to extract the title of the current program, it turns purple in stead of green and won't work.

what am i doig wrong now?

Code: Select all
set eyetv_description to ""
set eyetv_playerstate to ""
set eyetv_showtitle to ""

tell application "eyetv"
   if playing then
      set eyetv_playerstate to "playing"
      set programInfo to program info of player_window playing
      set eyetv_description to shortdescription of currentshow of programInfo
      set eyetv_showtitle to title of currentshow of programInfo
   else
      set eyetv_playerstate to "paused"
      set eyetv_description to "N/A"
      set eyetv_showtitle to "N/A"
   end if
end tell


what is wrong with this, this should work, but something goes wrong.

all help is appreciated.

Posted on
Tue Oct 16, 2012 1:14 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: need help with applescript

Not sure if this is the problem, but it looks like you have some capitalization problems - it should be "currentShow" not "currentshow".

And you don't say what exactly is wrong - does it not compile or does it compile and give an error when you run it or does it run and eyetv_showtitle doesn't get set correctly...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Oct 16, 2012 1:21 pm
henkjanvries offline
User avatar
Posts: 108
Joined: May 05, 2012

Re: need help with applescript

it runs, currentshow is ok, but it gives an error on the title bit.

the screenshot says it better.

somehow the titel bit is purple and not green, and therefor wont grab the string from program info
Attachments
Screen Shot 2012-10-16 at 9.24.40 PM.png
Screen Shot 2012-10-16 at 9.24.40 PM.png (107.98 KiB) Viewed 3614 times

Posted on
Tue Oct 16, 2012 1:27 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: need help with applescript

I was right - you have the capitalization wrong: "currentShow" and "shortDescription" - the S and D should be capitalized and you have them as lower case.

At least I think that's the problem. You may need to go to the EyeTV support site to get it worked out since this is their scripting.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Oct 16, 2012 1:29 pm
henkjanvries offline
User avatar
Posts: 108
Joined: May 05, 2012

Re: need help with applescript

when compiling, after capatalizing, it changes back to lowercase

Posted on
Tue Oct 16, 2012 1:31 pm
henkjanvries offline
User avatar
Posts: 108
Joined: May 05, 2012

Re: need help with applescript

ps shortdescription works and is put into variables in indigo now. but using the same line for the title it wont work eventhough title is in the same class as shortdescription

Posted on
Tue Oct 16, 2012 1:33 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: need help with applescript

Yeah - I think you'll want to contact EyeTV about that one.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Oct 16, 2012 1:36 pm
henkjanvries offline
User avatar
Posts: 108
Joined: May 05, 2012

Re: need help with applescript

haha, ok thanks for the help!

Posted on
Tue Oct 16, 2012 1:47 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: need help with applescript

I suppose it might be a scoping issue - try this instead:

Code: Select all
set eyetv_description to ""
set eyetv_playerstate to ""
set eyetv_showtitle to ""
set programInfo to ""

tell application "eyetv"
   if playing then
      set eyetv_playerstate to "playing"
      set programInfo to program info of player_window playing
   else
      set eyetv_playerstate to "paused"
      set eyetv_description to "N/A"
      set eyetv_showtitle to "N/A"
   end if
end tell

if (programInfo is not "") then
  set eyetv_description to shortdescription of currentShow of programInfo
  set eyetv_showtitle to title of currentShow of programInfo
end if


Basically, it looks like the word "title" is defined in the EyeTV application's scope. When you try to use it as a record name, it's getting confused (if so, it's a poor AppleScript terminology implementation). Doing it the above way takes the reference to the "title" record name out of the EyeTV application's scope so maybe it'll work correctly.

Maybe... ;)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Who is online

Users browsing this forum: No registered users and 25 guests