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
Related
I intented to export all my photos from Mac to any other environment and this suggestion finally provided the base to solve this with applescript. That way the photos are always scaled (getting bigger than the original) but at least it works.
I know it's long but as I struggled that long with this problem, so I post the whole working solution below as an answer. Maybe someone has a better suggestion. I have refused to reverse engineer the contents in sqlite tables Photos is using, as this just may change with the next version.
Problems are various
There is no guarantee how Photos walks through the albums and folders. And as it sometimes just stops working, you have to guarantee some order, or you will never finish. So I introduced a way to start at a particular album at a particular photo. The order within the album seems to be stable. The log output written shows the unique ids of album and photo (as names may not be unique) to be able to restart it at this point. Most of the time the second attempt just works.
I did not find a way to store photos in order, so I created one single directory for each photo and stored each photo in a separate directory, so I can reimport them in order. Problem is that Photos always uses the original file name and just counts upwards if the name exists already. Using different cameras just makes it worse.
All attributes I wrote into a text file per photo, so I can reimport them later.
Error handling is quite tricky. The photos library sometimes just requests the user to press a button, which makes it hard to script it.
That's unfortunately the best I was able to come up with, it is my 1st applescript. This worked on an old Mac with Sierra and it works on more recent versions with Catalina as well. I'm almost sure the newest version will not complain. I'm still searching for a better solution.
There is little support to run it from inside Apple's script editor, only command line provides all options.
#!/usr/bin/osascript
global startAlbum, startPhoto, match, dummy, match, photoCnt, infoFd
global errorIndicator
on writePhotoAndData(thePath, mediaItem, mediaAlbum)
set ind to "X"
using terms from application "Photos"
set fName to filename of mediaItem
set fId to id of mediaItem
set photoCnt to photoCnt + 1
-- export each media to separate directory -> only chance to keep the order
if dummy then
if infoFd ≠ missing value then
set s to id of mediaAlbum & tab & id of mediaItem & tab & thePath & linefeed as text
write s to infoFd as «class utf8»
end if
else
makeEmptyPosixPath(thePath)
set exportPath to POSIX file thePath
set infoFile to POSIX file (thePath & "/" & "info.txt")
set infoText to "id" & tab & id of mediaItem & linefeed & "file" & tab & filename of mediaItem & linefeed & "album" & tab & name of mediaAlbum & linefeed
if exists name of mediaItem then set infoText to infoText & "name" & tab & name of mediaItem & linefeed
if exists description of mediaItem then set infoText to infoText & "desc" & tab & description of mediaItem & linefeed
if exists date of mediaItem then
set d to date of mediaItem
set infoText to infoText & "date" & tab & short date string of d & space & time string of d & linefeed
end if
if exists altitude of mediaItem then set infoText to infoText & "alt" & tab & altitude of mediaItem & linefeed
if exists location of mediaItem then set infoText to infoText & "location" & tab & location of mediaItem & linefeed
if exists keywords of mediaItem then
tell mediaItem to set myKeywords to keywords
repeat with keyword in myKeywords
set infoText to infoText & "keyword" & tab & keyword & linefeed
end repeat
end if
set fd to open for access infoFile with write permission
set eof fd to 0 -- of fd?
write infoText to fd starting at eof as «class utf8»
close access fd
try
tell mediaAlbum
--Not sure whether this does anything, so removed
--set settings to "JPEG - Original Size"
export {mediaItem} to (exportPath as alias)
end tell
set errorIndicator to 0
on error errStr number errNum
if errNum = -1712 then --timeout
set ind to "E"
set errorIndicator to errorIndicator + 1
if errorIndicator >= 3 then
error "3 errors in a row - exiting"
end if
else
error errStr number errNum
end if
end try
end if
log ind & tab & photoCnt & tab & id of mediaAlbum & tab & id of mediaItem & tab & name of mediaAlbum & tab & filename of mediaItem
end using terms from
end writePhotoAndData
on walkAlbum(theAlbum, thePath)
if match = 0 then
if id of theAlbum = startAlbum then
set match to 1
if startPhoto is missing value then
set match to 2
end if
else
return
end if
else if match = 1 then
if id of theAlbum is not equal to startAlbum then
set match to 3
end if
end if
set photoNum to 0
using terms from application "Photos"
set albumPath to thePath & name of theAlbum & "/"
repeat with mediaItem in media items of theAlbum
set photoNum to photoNum + 1
if match = 1 then
if id of mediaItem = startPhoto then
set match to 2
end if
else if match = 2 then
set match to 3 --photo after the photo chosen
end if
if match = 3 then
writePhotoAndData(albumPath & photoNum, mediaItem, theAlbum)
end if
end repeat
end using terms from
end walkAlbum
on walkFolder(theFolder, thePath)
using terms from application "Photos"
repeat with containedFolder in folders of theFolder
walkFolder(containedFolder, thePath & name of containedFolder & "/")
end repeat
repeat with containedAlbum in albums of theFolder
walkAlbum(containedAlbum, thePath)
end repeat
end using terms from
end walkFolder
on makePosixPath(tPath)
do shell script "mkdir -p " & quoted form of tPath
end makePosixPath
on makeEmptyPosixPath(tPath)
do shell script "rm -rf " & quoted form of tPath & " && mkdir -p " & quoted form of tPath
end makeEmptyPosixPath
on makeFolder(tPath)
do shell script "mkdir -p " & quoted form of POSIX path of tPath
end makeFolder
on walkFile(fileName, fileOffset as integer)
set thisOffset to 0
set saveDelim to text item delimiters of AppleScript
set walkFd to open for access POSIX file fileName
set rawLine to read walkFd before linefeed as «class utf8»
repeat
set thisOffset to thisOffset + 1
if fileOffset = 0 or thisOffset ≥ fileOffset then
set thisLine to rawLine as text
set text item delimiters of AppleScript to tab
set splitLine to text items of thisLine
set text item delimiters of AppleScript to saveDelim
set albumIdString to item 1 of splitLine
set photoIdString to item 2 of splitLine
set pathString to item 3 of splitLine
tell application "Photos"
set thisAlbum to album id albumIdString
set thisMedia to media item id photoIdString
end tell
writePhotoAndData(pathString, thisMedia, thisAlbum)
log "O" & tab & thisOffset
end if
try
set rawLine to read walkFd before linefeed as «class utf8»
on error errTxt number errNum
if errNum = -39 then --end of file
exit repeat
else
error "Error reading inputfile: " & errTxt
end if
end try
end repeat
end walkFile
on run (args)
set caller to class of args as string
set errorIndicator to 0
set destPath to POSIX path of (get path to home folder) & "export/photos/"
set photoCnt to 0
set startAlbum to missing value
set startPhoto to missing value
set match to 3
set dummy to false
set walkFileName to missing value
set walkFileOffset to 0
set infoFd to missing value
set infoFileName to missing value
set chooseDestinationFolder to "Select start folder (defaults to " & destPath & ")"
set chooseStart to "Give start album and photo"
set chooseDryRun to "dry-run"
if caller = "script" then
log "Running in ScriptEditor:" & name of me
set options to choose from list {chooseDestinationFolder, chooseStart, chooseDryRun} with title "Configure run" with prompt "Select options" with multiple selections allowed and empty selection allowed
if options contains chooseDryRun then set dummy to true
if options contains chooseDestinationFolder then
try
set destFolder to choose folder with prompt "Choose export directory or cancel for default location" default location (get path to home folder as alias)
set destPath to POSIX path of destFolder
end try
end if
if options contains chooseStart then
set res to display dialog "Enter Id of album to start" default answer "" buttons {"OK"} default button 1
if length of text returned of res > 0 then
set startAlbum to text returned of res
set match to 0
end if
if match = 0 then
set res to display dialog "Enter id of photo to resume after (leave empty to start with album)" default answer "" buttons {"OK"} default button 1
if length of text returned of res > 0 then
set startPhoto to text returned of res
end if
end if
end if
else if caller = "list" then
log "Running on the command line:" & name of me
set cnt to 1
repeat while cnt ≤ length of args
if item cnt of args = "-t" then
set cnt to (cnt + 1)
set destPath to item cnt of args
set cnt to (cnt + 1)
else if item cnt of args = "-a" then
set match to 0
set cnt to (cnt + 1)
set startAlbum to item cnt of args
else if item cnt of args = "-p" then
set cnt to (cnt + 1)
set startPhoto to item cnt of args
else if item cnt of args = "-h" then
return name of me & " [-t target path] [-a start album id] [-a start photo id] [-d] [-i info file path]" & linefeed ¬
& name of me & "[-t target path] -f info file [-o offset]" & linefeed ¬
& name of me & " -h .. this help"
else if item cnt of args = "-d" then
set dummy to true
else if item cnt of args = "-i" then
set cnt to (cnt + 1)
set infoFileName to item cnt of args
else if item cnt of args = "-f" then
set cnt to (cnt + 1)
set walkFileName to item cnt of args
else if item cnt of args = "-o" then
set cnt to cnt + 1
set walkFileOffset to item cnt of args
else
error "Invalid option:" & item cnt of args & " - use -h for help"
end if
set cnt to (cnt + 1)
end repeat
end if
set mySettings to "Destination directory:" & destPath
if startAlbum is not missing value then set mySettings to mySettings & linefeed & tab & "Start album id:" & tab & startAlbum
if startPhoto is not missing value then set mySettings to mySettings & linefeed & tab & "Start photo id:" & tab & startPhoto
if infoFileName ≠ missing value then
set mySettings to mySettings & linefeed & tab & "Write file '" & infoFileName & "'" & linefeed
set dummy to true
end if
if dummy then set mySettings to mySettings & linefeed & tab & "Dry run only"
if caller = "script" then
display dialog mySettings with title "Start exporting?" with icon note
else if caller = "list" then
log mySettings
else
error "Internal error - caller interface unknown"
end if
if infoFileName ≠ missing value then
set infoFd to open for access POSIX file infoFileName with write permission
set eof infoFd to 1
end if
if walkFileName ≠ missing value then
walkFile(walkFileName, walkFileOffset)
else
walkFolder(application "Photos", destPath)
end if
if infoFd ≠ missing value then close access infoFd
return "Done!"
end run
I want to develop an Applescript to extract youtube live stream video ID using the Channel ID.
Currently, I'm doing it manually as Youtube changes live stream video ID time to time.
For an example, I'm practising following;
Open https://www.youtube.com/embed/live_stream?channel=UCu7cGbQEMgGk8TD0ZYucM5g
Right-click on the player and select "Copy video URL"
This URL is used to an Applescript I wrote to automate Livestreamer. (This script is given below.)
As Youtube changes this URL time to time, following script has to be changed the time to time. My intention is to automate the whole process.
-- Shraddha TV and Radio Recorder --
-- Developed by Anoma --
set pathToShraddha to ((path to downloads folder as text) & "Shraddha:")
set outputExtension to ""
set ls to ""
set sourceURL to ""
set con to ""
set windowInfo to ""
set theTime to ""
set endTime to ""
display dialog "Shraddha TV or Radio" buttons {"TV", "Radio", "Cancel"} default button 1
if result = {button returned:"TV"} then
set outputExtension to ".ts"
set sourceURL to "https://www.youtube.com/watch?v=1yv7JjMP4Dw"
set ls to "livestreamer"
set con to "480p -o"
else if result = {button returned:"Radio"} then
set outputExtension to ".mp3"
set sourceURL to "http://92.222.236.128:8006"
set ls to "ffmpeg -i"
set con to "-c copy"
else
return
end if
set fn to (setFileName(outputExtension))
display dialog "Record now or later?" buttons {"Now", "Later", "Cancel"} default button 1
if result = {button returned:"Now"} then
set endTime to text returned of (display dialog "Please set the time to end recording. (Leave 'hhmm' if you want to record continuously.) " with title "Timer" default answer "hhmm" buttons {"Cancel", "Set"} default button 2)
set windowInfo to recordMedia(ls, sourceURL, con, (POSIX path of pathToShraddha as string), fn)
finishTime(endTime, windowInfo)
else if result = {button returned:"Later"} then
-- get time to be set---
set theTime to text returned of (display dialog "Please set the time to start recording." with title "Timer" default answer "hhmm" buttons {"Cancel", "Set"} default button 2)
if ((theTime as string) is equal to "hhmm") then
display dialog "Time is not set correctly"
return
end if
set endTime to text returned of (display dialog "Please set the time to end recording. (Leave 'hhmm' if you want to record continuously.) " with title "Timer" default answer "hhmm" buttons {"Cancel", "Set"} default button 2)
display dialog (getTimeInHoursAndMinutes())
display dialog theTime
set i to 0
repeat while (getTimeInHoursAndMinutes()) is less than theTime
if (i = 0) then
set i to (i + 1)
recordMedia("", "", "", "", "")
end if
delay 60
end repeat
finishTime(endTime, (recordMedia(ls, sourceURL, con, (POSIX path of pathToShraddha as string), fn)))
else
return
end if
-- This method generates the file name
on setFileName(outputExt)
set fileName to do shell script "date +'%Y-%m-%d_%H-%M-%S'"
set outputExt to the outputExt as string
set fileName to ("STV_" & fileName as string) & outputExt
return fileName as string
end setFileName
-- This method gives the current time in "hhmm" format (24hr)
on getTimeInHoursAndMinutes()
set timeStr to time string of (current date)
set hrStr to (characters 1 thru -10 of timeStr as string)
if ((count hrStr) is less than 2) then
set timeStr to ((0 & timeStr) as string)
end if
set ampm to (characters -2 thru -1 of timeStr as string)
if ((ampm as string) is equal to "PM") then
if ((hrStr as integer) is less than 12) then
set hrStr to (((hrStr as integer) + 12) as string)
end if
else
if ((hrStr as integer) = 12) then
set hrStr to (0 as string)
end if
if ((count hrStr) is less than 2) then
set hrStr to ((0 & hrStr) as string)
end if
end if
set mStr to (characters 4 thru 5 of timeStr as string)
set timeStr to (hrStr) & (mStr)
return timeStr as string
end getTimeInHoursAndMinutes
-- This method Record the stream --
on recordMedia(ls, sourceURL, con, pathToShraddhaString, fn)
tell application "Terminal"
set windowInfo to do script "caffeinate -i " & ls & space & sourceURL & space & con & space & pathToShraddhaString & fn
activate of windowInfo
end tell
return windowInfo
end recordMedia
-- This method end recording --
on finishTime(endTime, windowInfo)
if ((endTime as string) is equal to "hhmm") then
else
repeat while (getTimeInHoursAndMinutes()) is less than endTime
delay 60
end repeat
tell application "Terminal"
-- reopen
activate of windowInfo
--tell application "System Events" to keystroke "q"
tell application "System Events" to keystroke "c" using {control down}
end tell
end if
end finishTime
Could you please help me in developing the script to automate the extraction of the Livestream URL every time I run the script?
Thank you.
This is the answer given by Capitainos # Superuser.
It works really fine.
Property LivestreamURL : {}
-- set youtube_channel to choose URL -- just remove comment tag to choose this option
set youtube_channel to "https://www.youtube.com/embed/live_stream?channel=UCu7cGbQEMgGk8TD0ZYucM5g"
tell application "Safari"
launch -- background OR use 'activate' if preferred
open location youtube_channel
end tell
-- wait for Safari to load the webpage
if load_webpage(20) is false then return
tell application "Safari" to set end of LivestreamURL to do JavaScript "document.links[0].href" in document 1
set this_ID to item 1 of LivestreamURL
set channel_ID to (characters 51 thru -1 of youtube_channel) as string
set video_ID to (characters 33 thru -1 of this_ID) as string
-- return LivestreamURL -- or;
return return & "Channel ID : " & channel_ID & linefeed & "Video ID : " & video_ID & linefeed & linefeed
-- This is the Handler 'load_webpage'
on load_webpage(timeout_variable)
delay 2
repeat with i from 1 to the timeout_variable
tell application "Safari"
if (do JavaScript "document.readyState" in document 1) is "complete" then
return true
else if i is the timeout_variable then
return false
else
delay 1
end if
end tell
end repeat
return false
end load_webpage
i need help with my applescript program
set UnixPath to POSIX path of ((path to me as text) & "::")
set term to get id of application "Terminal"
on notify(t)
display notification t
end notify
notify("starting " & term)
to replaceText(someText, oldItem, newItem)
(*
replace all occurances of oldItem with newItem
parameters - someText [text]: the text containing the item(s) to change
oldItem [text, list of text]: the item to be replaced
newItem [text]: the item to replace with
returns [text]: the text with the item(s) replaced
*)
set {tempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, oldItem}
try
set {itemList, AppleScript's text item delimiters} to {text items of someText, newItem}
set {someText, AppleScript's text item delimiters} to {itemList as text, tempTID}
on error errorMessage number errorNumber -- oops
set AppleScript's text item delimiters to tempTID
error errorMessage number errorNumber -- pass it on
end try
return someText
end replaceText
on getMyName()
set myPath to path to me as text
if myPath ends with ":" then
set n to -2
else
set n to -1
end if
set AppleScript's text item delimiters to ":"
set myName to text item n of myPath
if (myName contains ".") then
set AppleScript's text item delimiters to "."
set myName to text 1 thru text item -2 of myName
end if
set AppleScript's text item delimiters to ""
return myName
end getMyName
set nameToFix to getMyName()
set bufferedName to replaceText(nameToFix, " ", "\\ ")
set lua to UnixPath & bufferdName & ".app/Contents/Resources/" & "lua"
set programSet to UnixPath & bufferdName & ".app/Contents/Resources/Scripts/lua_program.lua"
set mainComand to "program_app_temp/lua_program.lua"
set do to "dofile(" & quoted form of mainComand & ")"
tell application "Terminal"
activate
tell application "System Events"
keystroke "mkdir ~/ai_app_temp"
keystroke return
keystroke "cp " & ai & " ~/ai_app_temp/"
keystroke return
keystroke lua
keystroke return
keystroke do
delay 1
keystroke return
end tell
end tell
when i run my program it hits an error and says
error "The variable bufferdName is not defined." number -2753 from "bufferdName" . how do i fix that? i am new to applescript
It looks like a simple spelling mistake. Look carefully at the spelling in these lines of code
set bufferedName to replaceText(nameToFix, " ", "\\ ")
set lua to UnixPath & bufferdName & ".app/Contents/Resources/" & "lua"
set programSet to UnixPath & bufferdName & ".app/Contents/Resources/Scripts/lua_program.lua"
bufferedName is the variable you set, but you are using bufferdName <-- spelled differently
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).
Question: I would like to run an applescript against a list of selected messages in Apple OS X Mail.
Right now, the script I wrote will work on a single selection only, so I am guessing the issue is how to loop it for all items selected. Any help would be appreciated.
Here is the script:
tell application "Mail"
set theSelection to selection
set theSelectedMessage to item 1 of theSelection
set theSelectedMessageSender to sender of theSelectedMessage
set theSelectedMessageRecipient to address of to recipients of theSelectedMessage
set theSelectedMessageSenderName to extract name from sender of theSelectedMessage
set theSelectedMessageSenderAddress to extract address from sender of theSelectedMessage
set theSelectedMessageSubject to subject of theSelectedMessage
set theSelectedMessageContent to content of theSelectedMessage
set MessageText to ¬
"This email (" & theSelectedMessageRecipient & ") does NOT ¬
care to receive emails regarding this matter." & return & return & ¬
"This email was originally delivered to: " & ¬
theSelectedMessageRecipient & return & return & ¬
"Remove this email from your list: " & ¬
theSelectedMessageRecipient & ¬
return & return & ¬
"---------- ORIGINAL MESSAGE ----------------"
set theMessage to make new outgoing message with properties {visible:true, subject:"REMOVE: RE:" & theSelectedMessageSubject, content:MessageText & theSelectedMessageContent, reply to:theSelectedMessageRecipient}
tell theMessage
make new to recipient at end of to recipients with properties {name:theSelectedMessageSenderName, address:theSelectedMessageSenderAddress}
end tell
end tell
set theSelectedMessage to item 1 of theSelection
Replace this with:
repeat with theSelectedMessage in theSelection
Just before the last line, add:
end repeat