Applescript, basic help please! (Trying to control Elgato EyeTV) - applescript

I am very new to applescript and am working based off of a script I received from someone else, but I am having issues changing the channel with an application I created using Interface Builder from XCode for the application EyeTV by Elgato. I keep getting an error saying "command /usr/bin/osacompile failed with exit code 1". I included the code below
global theChannel
global theApp
global theMachine
property theMachine : "10.0.2.2"
on change_channel(channel_number)
set theChannel channel_number as integer
tell application "EyeTV" of machine theMachine
«event EyTVChch» given «class Chnm»: theChannel
end tell
end change_channel
on clicked theObject
set theApp to application "EyeTV" of machine theMachine
if name of theObject is "fox" then
change_channel(2)
else if name of theObject is "cbs" then
change_channel(3)
else if name of theObject is "nbc" then
change_channel(4)
else if name of theObject is "pbs" then
change_channel(5)
else if name of theObject is "cw" then
change_channel(6)
else if name of theObject is "abc" then
change_channel(7)
else if name of theObject is "twc" then
change_channel(9)
else if name of theObject is "bt" then
change_channel(10)
else if name of theObject is "fs" then
change_channel(11)
else if name of theObject is "cs" then
change_channel(12)
else if name of theObject is "espn" then
change_channel(13)
else if name of theObject is "espn2" then
change_channel(14)
else if name of theObject is "espnu" then
change_channel(15)
else if name of theObject is "dh" then
change_channel(20)
else if name of theObject is "dc" then
change_channel(29)
else if name of theObject is "tlc" then
change_channel(30)
else if name of theObject is "sc" then
change_channel(31)
else if name of theObject is "ng" then
change_channel(32)
else if name of theObject is "hc" then
change_channel(33)
else if name of theObject is "fn" then
change_channel(34)
else if name of theObject is "msnbc" then
change_channel(35)
else if name of theObject is "cnbc" then
change_channel(36)
else if name of theObject is "hn" then
change_channel(37)
else if name of theObject is "cnn" then
change_channel(39)
else if name of theObject is "cspan2" then
change_channel(41)
else if name of theObject is "cspan" then
change_channel(42)
else if name of theObject is "rc" then
change_channel(53)
else if name of theObject is "wolv" then
change_channel(55)
else if name of theObject is "rham" then
change_channel(56)
else if name of theObject is "rctv" then
change_channel(57)
else if name of theObject is "rlc" then
change_channel(58)
end if
end clicked
on will finish launching theObject
tell window "Main"
set theAddress to text returned of (display dialog "Enter the IP of the remote computer:" default answer "10.0.2.2" default button 2)
set theMachine to "eppc://" & theAddress
end tell
set theApp to application "EyeTV" of machine theMachine
using terms from application "Script Editor"
tell theApp
activate
if «class Fuls» is true then
set title_fullscreen to "Exit Full Screen"
else if «class Fuls» is false then
set title_fullscreen to "Enter Full Screen"
end if
set theChannel to «class Crch»
end tell
end using terms from
tell window "Main"
set title of button "fullscreen" to title_fullscreen
set the contents of text field "channel_number" to theChannel
set title of button "eyetv_quit" to "Quit EyeTV"
set isOpen to 1 as integer
end tell
end will finish launching
on will close theObject
quit
end will close

You have a number of syntax errors in your script. Try pasting the script into the AppleScript Script Editor and hitting "Compile". Here's a few I found:
set theChannel channel_number as integer
should be:
set theChannel to channel_number as integer
on clicked theObject
should be:
on clicked(theObject)
on will finish launching theObject
is a syntax error, but I'm not sure what the solution is... I also got a few more syntax errors, and the syntax looked correct so I think it might just be that I don't have EyeTV.

Related

Applescript selection name extension

i got problem for the name extension of selection
it not work when i select more then 2 different files type
please help
property doc_list : {"pdf", "doc"}
property image_list : {"jpg", "png", "tif", "tiff", "gif"}
tell application "Finder"
set sel to (get selection)
repeat with AnItem in sel
end repeat
if sel = {} then
display alert ("nothing selected")
else if name extension of AnItem is in doc_list then
display alert ("this is doc files")
else if name extension of AnItem is in image_list then
display alert ("this is images files")
else if name extension of AnItem is in image_list & doc_list then
display alert ("this is images and doc files")
else if name extension of AnItem is not in image_list & doc_list then
display alert ("unknown file type")
end if
end tell
The end repeat line must be moved to before end tell.
This is a slightly improved version. The third else if clause will never be reached and the fourth can be just else
property doc_list : {"pdf", "doc"}
property image_list : {"jpg", "png", "tif", "tiff", "gif"}
tell application "Finder"
set sel to (get selection)
if sel = {} then
display alert ("nothing selected")
return
end if
repeat with AnItem in sel
set nameExtension to name extension of AnItem
if nameExtension is in doc_list then
display alert ("this is doc files")
else if nameExtension is in image_list then
display alert ("this is images files")
else
display alert ("unknown file type " & quote & nameExtension & quote)
end if
end repeat
end tell

Add files to iTunes playlist

Sorry if it has already discussed but I'm unable to find an answer.
I would like to add files from a choosen folder to an existing iTunes' playlist.
I don't want to copy/duplicate these files (so iTunes would create a new folder inside its Music folder).
If I use:
add myFolder to playlist playListName
songs are duplicated in a new "Music" folder
If I use:
add myFile to playlist playListName
I have a type error, something about «class cUsP» id 20647 of «class cSrc» id 66 of application "iTunes".
My app code contains several subroutines, not easy to understand unless I post the entire code.
myFolder can be defined by dropping a folder onto the app, or by command choose folder.
Then, playListName is extracted from the choosen folder's pathname.
Then, folder is processed like this, in order to create playlist:
on processFolder(thisFolder, playListName)
tell application "iTunes"
activate
-------------------------------- create playlist
try
set newPlaylist to (make new user playlist with properties {name:playListName})
set view of browser window 1 to newPlaylist
on error errMsg
beep
my dlog("Unable to create playlist " & my kwote(playListName) & "." & return & return & errMsg, {"Abort"}, appTitle, "error")
return false
end try
--***add thisFolder to newPlaylist -- create new "Music folder" and duplicate files !!!
--------------- add files --> tracks
tell application "Finder"
repeat with thisFile in (get every file of folder thisFolder)
if (my isValidFile(thisFile)) then
tell application "iTunes"
try
add thisFile to playlist playListName -- ERROR !!!
on error errMsg
beep
my dlog("Unable to add file " & my kwote(thisFile as text) & "." & return & return & errMsg, {"Abort"}, appTitle, "error")
return false
end try
end tell
end if
end repeat
end tell
return true
end tell
end processFolder
on isValidFile(thisFile)
tell application "Finder"
set the fileInfo to (info for thisFile as alias)
if (mp3Check) then
if (alias of the fileInfo is false) and ((the file type of the fileInfo is in the typesList) or (the name extension of the fileInfo is in the extensionsList)) then return true
else
if (alias of the fileInfo is false) then return true
end if
return false
end tell
end isValidFile
Thank you.

Automatically add incoming call to the conference using Skype API on Mac

I am trying to write an AppleScript which will start the Skype and call who are online and add incoming calls automatically after the conference is started. I am stuck at the last part of this implementation (starred in the code below). The code that is in the repeat loop.
Can you please help me implement a way to add the incoming calls to the existing conference call without putting the call on hold?
Thanks in advance!
My system is Mac OS X Lion (10.7.5)
PS. I have got a lot of help from other people's works so far. That's how I could do this much.
tell application "System Events"
set powerCheck to ((application processes whose (name is equal to "Skype")) count)
if powerCheck = 0 then
my launch_skype()
else if powerCheck = 1 then
return
end if
end tell
## FUNCTIONS ##
on dismiss_skype_api_security()
tell application "System Events" to tell process "Skype"
set window_name to "Skype API Security"
set ok_text to "OK"
set radio_text to "Allow this application to use Skype"
tell application "System Events" to tell process "Skype"
if window window_name exists then
click radio button radio_text of radio group 1 of window window_name
delay 2
click button ok_text of window window_name
end if
end tell
delay 1
end tell
end dismiss_skype_api_security
on launch_skype()
tell application "Skype"
set statusList to {"RINGING", "ROUTING", "UNPLACED"}
delay 2
try
set status to "COMMAND_PENDING"
repeat until status is not equal to "COMMAND_PENDING"
set status to send command "GET USERSTATUS" script name "auto call"
if status is equal to "COMMAND_PENDING" then
my dismiss_skype_api_security()
end if
end repeat
#### CALL ONLINE CONTACTS + AUTO ACCEPT ####
activate
delay 1
set OnlineContacts to my get_online_contacts()
delay 1
send command "CALL " & OnlineContacts script name "auto call"
delay 2
-- Set first call ID as master
set firstCall to send command "SEARCH ACTIVECALLS" script name "auto call"
set firstCallID to last word of firstCall -- What if the last guy leaves the call ?!?!?
set firstStatus to send command "GET CALL " & firstCallID & " STATUS" script name "auto call"
if statusList contains the last word of firstStatus then -- First Call
set MasterCallID to firstCallID
end if
**set callID to ""
repeat until callID is "CALLS"
delay 3
set status to send command "GET CALL " & firstCallID & " STATUS" script name "auto call"
if the last word of status is "RINGING" then --Someone is calling to join the call
set calls to send command "SEARCH ACTIVECALLS" script name "auto call"
set callID to last word of calls
--send command "ALTER CALL " & callID & " JOIN_CONFERENCE " & mainCallID script name --"auto call"
end if
end repeat**
on error number -2753
quit
end try
end tell
end launch_skype
### GET ONLINE CONTACTS ###
on get_online_contacts()
global OnlineFriends
set OnlineFriends to {}
tell application "Skype"
set SkypeStatus to send command "GET CONNSTATUS" script name "auto call"
if SkypeStatus is "CONNSTATUS ONLINE" then
set AppleScript's text item delimiters to " "
set Friends to send command "SEARCH FRIENDS" script name "auto call"
set Friends to my ReplaceString(Friends, " ", ",")
set Friends to my ReplaceString(Friends, ",,", ",")
set FriendsList to my SplitList(Friends, ",")
set NumFriends to number of items in FriendsList
repeat with i in FriendsList
if (i begins with "DISABLEDxmpp:") or (i begins with "USERS") or (i begins with "ugur") or (i is "echo123") or (i begins with "esr") or (i begins with "ayt") or (i begins with "Zaf") then
else
set FriendStatus to send command "GET USER " & i & " ONLINESTATUS" script name "auto call"
if text item 4 of FriendStatus is "ONLINE" then
set aUser to i
set aUser to my JoinList(aUser, " ")
set end of OnlineFriends to aUser
end if
end if
end repeat
if (count OnlineFriends) > 0 then
set OnlineFriends to my JoinList(OnlineFriends, ", ")
else
set beginning of OnlineFriends to "No Skype Friends online at this time."
end if
else
set beginning of OnlineFriends to "Skype is offline."
end if
end tell
return OnlineFriends
end get_online_contacts
on JoinList(l, del)
set RetVal to ""
set OldDel to AppleScript's text item delimiters
set AppleScript's text item delimiters to del
set RetVal to l as string
set AppleScript's text item delimiters to OldDel
return RetVal
end JoinList
on SplitList(t, del)
set RetVal to {}
set OldDel to AppleScript's text item delimiters
set AppleScript's text item delimiters to del
set RetVal to every text item of t
set AppleScript's text item delimiters to OldDel
return RetVal
end SplitList
on ReplaceString(theText, oldString, newString)
set OldDel to AppleScript's text item delimiters
set AppleScript's text item delimiters to oldString
set tempList to every text item of theText
set AppleScript's text item delimiters to newString
set theText to the tempList as string
set AppleScript's text item delimiters to OldDel
return theText
end ReplaceString

AppleScript - Skype Interface

I am very new to AppleScript. I found this script to use with a GeekTool Geeklet to show the online Skype users. When I run the AppleScript I get an error that "skype_id" is undefined. I cannot find where/why it is undefined. Apparently this same script worked in the past.
Here is the error:
error "The variable skype_id is not defined." number -2753 from "skype_id"
Here is the script:
on remvix(ix, ls)
if ls is {} then
return {}
else if ix is 1 then
return rest of ls
else
return {item 1 of ls} & remvix(ix - 1, rest of ls)
end if
end remvix
on tail(astring, k)
return do shell script "echo '" & astring & "' | awk '{{i = " & k & "; while ( i <= NF-1 ) {printf $i \" \"; i++}; printf $i}}'"
end tail
property onlinegroup : 0
on getgroup()
tell application "Skype"
if my checkgroup(onlinegroup) is true then
return onlinegroup
else
set hardwired to send command "search groups hardwired" script name "online users"
set hardwired to my tail(hardwired, 2)
set hardwired to text items of hardwired
repeat with i in hardwired
if my checkgroup(i) is true then
return i
end if
end repeat
end if
end tell
end getgroup
on checkgroup(group_id)
tell application "Skype"
set grouptype to send command "get group " & group_id & " type" script name "online users"
set grouptype to my tail(grouptype, 4)
if grouptype is "ONLINE_FRIENDS" then
return true
else
return false
end if
end tell
end checkgroup
property dropped : 0
set text item delimiters to ", "
set onlineusers to {}
tell application "System Events"
set powerCheck to ((application processes whose (name is equal to "Skype")) count)
if powerCheck = 0 then
set end of onlineusers to " Skype not running"
else
tell application "Skype"
set onlinegroup to my getgroup()
set skype_id to send command "get group " & onlinegroup & " users" script name "online users"
set skype_id to my tail(skype_id, 4)
set skype_id to text items of skype_id
repeat with j from 1 to count skype_id
if item j of skype_id is "echo123" then
set skype_id_new to my remvix(j, skype_id)
set dropped to 1
end if
end repeat
if dropped is 1 then
set skype_id to skype_id_new
end if
repeat with i in skype_id
set aUser to send command "get user " & i & " fullname" script name "online users"
set aUser to my tail(aUser, 4)
if aUser is "" then set aUser to i
set amoodtext to send command "get user " & i & " mood_text" script name "online users"
set amoodtext to my tail(amoodtext, 4)
if amoodtext is "" then
set end of onlineusers to aUser
else
set end of onlineusers to aUser & " (" & amoodtext & ")"
end if
end repeat
if (count skype_id) > 0 then
set item 1 of onlineusers to " " & item 1 of onlineusers
else
set beginning of onlineusers to " No Contacts Online"
end if
return onlineusers
end tell
end if
end tell
Thanks in advance for your help.
'my tail' is the script's own function/handler, which is just a wrapper for an awk (shell) script. For some reason that function is failing to return anything, and I notice that it includes no error checking. It would be useful to start debugging the 'on tail' chunk. For example, are the parameters astring and k meaningful? This error handling code could slot into the beginning of the tail handler:
if ((class of astring) is not string) or ((class of k) is not integer) then
display dialog "Screwy parameter sent to tail" buttons {"Rats"} default button 1
error number -128 -- abort script entirely
end if
If that doesn't find the error, then maybe awk is misbehaving, which seems unlikely, but could still be possible I suppose.
Just a general observation. I know appleScript is suppose to be a friendly, easy going language (although it isn't), and you probably got this script from someone else, but for debugging purposes, you are asking for trouble by redefining the skype_id variable so many times. (This is the reason for Chuck's response).

Reading lyrics from itune to make a file

I got hints from http://www.dougscripts.com/itunes/ to come up with the following code. But it needs much more improvements.
I got error when I'm done with the file generation, http://a.imageshack.us/img831/1610/screenshot20100804at113l.png, what's wrong?
I don't need to use "TextEdit" for storing a file, is there better way just store the info to the file?
tell application "iTunes"
if player state is playing then
set sel to current track as list
else if selection is not {} then
set sel to selection
end if
set noSong to ""
set summaryFile to ((path to desktop as Unicode text) & "songs2.txt")
set ff to open for access file summaryFile with write permission
repeat with this_track in sel
set the_lyrics to this_track's lyrics
set {art, nom} to {this_track's artist, this_track's name}
if the_lyrics is not "" then
tell application "TextEdit"
activate
set myVar to art & nom & the_lyrics
write myVar to ff starting at eof
end tell
else
beep
end if
end repeat
end tell
Here are two subroutines I use to manage writing data to a text file:
on WriteLog(the_text)
set this_story to the_text
set this_file to (((path to desktop folder) as text) & "MY STORY")
my write_to_file(this_story, this_file, true)
end WriteLog
on write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
Please note write_to_file() is Apple's code from their own old Applescript site in Essential Subroutines. WriteToLog() is my own subroutine that wrote to interface with write_to_file with only one argument, the text itself. Add salt to taste. To rewrite the script accomodate the above subroutines, I would do it like this:
tell application "iTunes"
if player state is playing then
set sel to current track as list
else if selection is not {} then
set sel to selection
end if
set noSong to ""
repeat with this_track in sel
set the_lyrics to this_track's lyrics
set {art, nom} to {this_track's artist, this_track's name}
if the_lyrics is not "" then
set myVar to art & nom & the_lyrics
my WriteLog(myVar)
else
beep
end if
end repeat
end tell
you just had some things out of scope all the opening closing and writing of the text file must be done outside of itunes and texedit is not needed
set summaryFile to ((path to desktop as Unicode text) & "songs2.txt")
try
close access (summaryFile as alias) -- close the file if its open alreayd
end try
set ff to open for access file summaryFile with write permission
tell application "iTunes"
if player state is playing then
set sel to current track as list
else if selection is not {} then
set sel to selection
end if
set noSong to ""
repeat with this_track in sel
set the_lyrics to lyrics of this_track
set {art, nom} to {artist of this_track, name of this_track}
if the_lyrics is not "" then
tell me
set myVar to art & nom & the_lyrics
write myVar to ff starting at eof
end tell
else
beep
end if
end repeat
end tell
close access (summaryFile as alias)

Resources