AppleScript Error on Upgrade to Monterey – Mass SMS Text Application - macos

Hoping someone can help with this – I'm running macOS Monterey on an Apple M1 Pro laptop. My AppleScript to send out batch text messages, stored on an Excel file, delivered through the Messages app is now not working – it worked fine on my old laptop operating under Catalina.
The problem appears to be in delivering the phone number ("targetBuddyPhone") into the proper location in the Messages app. Instead, the text message ("targetMessage") is being dropped into the recipient location in the app. Does anyone have any ideas on possible solutions?
Thanks in advance.
on run {input, parameters}
set phoneCol to "B"
set messageCol to "C"
set startRow to 1
set counter to "D"
set xlsFilePath to (path to desktop as text) & "texttest.xlsx"
tell application "Microsoft Excel" to open file xlsFilePath
tell application "Microsoft Excel"
set endRow to value of cell (counter & startRow) as number
end tell
repeat with thisRow from startRow to endRow
tell application "Microsoft Excel"
set targetBuddyPhone to string value of cell (phoneCol & thisRow) as string
set targetMessage to value of cell (messageCol & thisRow) as string
end tell
activate application "Messages"
tell application "System Events" to tell process "Messages"
key code 45 using command down -- press Command + N to start a new window
keystroke targetBuddyPhone -- input the phone number
key code 36 -- press Enter to focus on the message area
delay 3
keystroke targetMessage -- type some message
key code 36 -- press Enter to send
end tell
delay 6
end repeat
return input
end run

Since GUI scripting is always tightly tied to the version of the application, I recommend getting rid of it once and for all and using the following more durable solution:
on run {input, parameters}
set phoneCol to "B"
set messageCol to "C"
set startRow to 1
set counter to "D"
set xlsFilePath to (path to desktop as text) & "texttest.xlsx"
tell application "Microsoft Excel"
open file xlsFilePath
set endRow to value of cell (counter & startRow) as number
end tell
tell application "Messages"
activate
set SMSService to service named "SMS" -- YOU NEED THIS SERVICE
end tell
repeat with thisRow from startRow to endRow
tell application "Microsoft Excel"
set targetBuddyPhone to string value of cell (phoneCol & thisRow) as string
set targetMessage to value of cell (messageCol & thisRow) as string
end tell
tell application "Messages"
set theBuddy to buddy targetBuddyPhone of SMSService
send targetMessage to theBuddy
end tell
end repeat
return input
end run

I figured out the solution. To my GUI-based approach, I inserted delays into the script, which solved the problems.
on run {input, parameters}
set phoneCol to "B"
set messageCol to "C"
set startRow to 1
set counter to "D"
set xlsFilePath to (path to desktop as text) & "texttest.xlsx"
tell application "Microsoft Excel" to open file xlsFilePath
tell application "Microsoft Excel"
set endRow to value of cell (counter & startRow) as number
end tell
repeat with thisRow from startRow to endRow
tell application "Microsoft Excel"
set targetBuddyPhone to string value of cell (phoneCol & thisRow) as string
set targetMessage to value of cell (messageCol & thisRow) as string
end tell
activate application "Messages"
tell application "System Events" to tell process "Messages"
key code 45 using command down -- press Command + N to start a new window
delay 3
keystroke targetBuddyPhone -- input the phone number
delay 3
key code 36
delay 3
key code 36 -- press Enter to focus on the message area
delay 3
keystroke targetMessage -- type some message
delay 3
key code 36 -- press Enter to send
end tell
delay 6
end repeat
return input
end run
To Robert's solution, I changed one line (set SMSService to ...) and this script now works properly.
on run {input, parameters}
set phoneCol to "B"
set messageCol to "C"
set startRow to 1
set counter to "D"
set xlsFilePath to (path to desktop as text) & "texttest.xlsx"
tell application "Microsoft Excel"
open file xlsFilePath
set endRow to value of cell (counter & startRow) as number
end tell
tell application "Messages"
activate
set SMSService to 1st account whose service type = SMS -- YOU NEED THIS SERVICE
end tell
repeat with thisRow from startRow to endRow
tell application "Microsoft Excel"
set targetBuddyPhone to string value of cell (phoneCol & thisRow) as string
set targetMessage to value of cell (messageCol & thisRow) as string
end tell
tell application "Messages"
set theBuddy to participant targetBuddyPhone of SMSService
send targetMessage to theBuddy
end tell
end repeat
return input
end run

Related

Applescript to extract YouTube Livestream Video ID

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

Upload random file hourly with photos.app and applescript

I have baby photos in a folder and I want to upload them one at a time about every hour (4000 secs not 3600 secs) to a shared iCloud album that all my relatives see on their iPhones and iPads and macs. Here is my applescript saved as an application with the keep open box checked. I think it's not quite right. What's wrong?
on idle
set importFolder to "Amac:Users:AbuDavid:Downloads:uploadBABY"
set extensionsList to {"jpg", "png", "tiff"}
tell application "Finder" to set theFiles to some file of importFolder whose name extension is in extensionsList
if (count of theFiles) < 1 then
display dialog "No images selected!" buttons "OK"
else
set albumName to "BabyDouDou"
set timeNow to time string of (current date)
set today to date string of (current date)
set albumName to albumName & " " & timeNow & " " & today
set imageList to theFiles
tell application "Photos"
activate
delay 2
import imageList into albumName skip check duplicates yes
end tell
tell application "Finder" to move theFiles to trash
end if
return 4000
end idle
There are some issues:
The Finder needs the keyword folder – not just a literal string – to specify a folder.
some file returns always one file so the count command fails and returns always 0.
albumName is a literal string as well rather than a object specifier.
Photos.app expects alias specifiers for the files to be imported rather than Finder object specifiers.
Try this
on idle
set importFolder to (path to downloads folder as text) & "uploadBABY"
set extensionsList to {"jpg", "png", "tiff"}
tell application "Finder" to set theFiles to files of folder importFolder whose name extension is in extensionsList
if (count theFiles) < 1 then
display dialog "No images selected!" buttons "OK"
else
set theFile to some item of theFiles
set albumName to "BabyDouDou"
set timeNow to time string of (current date)
set today to date string of (current date)
set albumName to albumName & " " & timeNow & " " & today
set imageList to {theFile as alias}
tell application "Photos"
activate
delay 2
if not (exists container albumName) then
set theAlbum to make new album
set name of theAlbum to albumName
else
set theAlbum to container albumName
end if
import imageList into theAlbum skip check duplicates yes
end tell
tell application "Finder" to move theFiles to trash
end if
return 4000
end idle
Made a small change to only delete the image that was uploaded and not all the images. Thank you so much.
on idle
set importFolder to (path to downloads folder as text) & "uploadBABY"
set extensionsList to {"jpg", "png", "tiff"}
tell application "Finder" to set theFiles to files of folder importFolder whose name extension is in extensionsList
if (count theFiles) < 1 then
display dialog "No images selected!" buttons "OK"
else
set theFile to some item of theFiles
set albumName to "testscript"
set imageList to {theFile as alias}
tell application "Photos"
activate
delay 2
if not (exists container albumName) then
set theAlbum to make new album
set name of theAlbum to albumName
else
set theAlbum to container albumName
end if
import imageList into theAlbum skip check duplicates yes
end tell
tell application "Finder" to move theFile to trash
end if
return 7
end idle

Creating new space/desktop in OSX with applescript?

Since OSX seems to lack a keyboard shortcut to create a new space/desktop, I'm wondering if this could be accomplished creating an applescript and binding that to a keyboard shortcut.
Looked a ton on google and couldn't find anything. Surprised no one has asked this before... seems like it would be something that lots of people would find very useful.
Here are the list of AppleScript Spaces routines I found online ::
--my get_spaces_enabled()
--my set_spaces_enabled(enable_spaces)
--my toggle_spaces_enabled()
--my get_spaces_rows()
--my set_spaces_rows(row_count)
--my get_spaces_columns()
--my set_spaces_columns(column_count)
--my get_spaces_count()
--my show_all_spaces()
--my get_spaces_application_bindings()
--my set_spaces_application_bindings(new_bindings)
--my collect_application_in_current_space(application_bundle_id)
--my set_spaces_application_binding_for_application(application_bundle_id, chosen_space)
--my get_space_binding_for_application(application_bundle_id)
--my choose_space_for_current_application()
--my choose_space_for_application(application_bundle_id)
--my remove_spaces_application_binding(application_bundle_id)
--my get_spaces_arrow_key_modifiers()
--my get_spaces_numbers_key_modifiers()
--my switch_to_space(space_number)
--my open_spaces_preferences()
--my display_spaces_not_enabled_error()
on get_spaces_enabled()
tell application "System Events" to tell spaces preferences of expose preferences to return (get spaces enabled)
end get_spaces_enabled
on set_spaces_enabled(enable_spaces)
tell application "System Events" to tell spaces preferences of expose preferences to set spaces enabled to enable_spaces
end set_spaces_enabled
on toggle_spaces_enabled()
my set_spaces_enabled(not (my get_spaces_enabled()))
end toggle_spaces_enabled
on get_spaces_rows()
tell application "System Events" to tell spaces preferences of expose preferences to return (get spaces rows)
end get_spaces_rows
on set_spaces_rows(row_count)
tell application "System Events" to tell spaces preferences of expose preferences to set spaces rows to row_count
end set_spaces_rows
on get_spaces_columns()
tell application "System Events" to tell spaces preferences of expose preferences to return (get spaces columns)
end get_spaces_columns
on set_spaces_columns(column_count)
tell application "System Events" to tell spaces preferences of expose preferences to set spaces columns to column_count
end set_spaces_columns
on get_spaces_count()
return ((my get_spaces_rows()) * (my get_spaces_columns()))
end get_spaces_count
on show_all_spaces()
try
tell application "Finder" to set spaces_app_path to (application file id "com.apple.spaceslauncher") as string
do shell script "open " & quoted form of POSIX path of spaces_app_path
end try
end show_all_spaces
on get_spaces_application_bindings()
tell application "System Events" to tell spaces preferences of expose preferences to return (get application bindings)
end get_spaces_application_bindings
on set_spaces_application_bindings(new_bindings)
tell application "System Events" to tell spaces preferences of expose preferences to set application bindings to new_bindings
end set_spaces_application_bindings
on collect_application_in_current_space(application_bundle_id)
set application_bundle_id to my make_lowercase(application_bundle_id)
set app_bindings to my get_spaces_application_bindings()
my set_spaces_application_bindings((run script "{|" & application_bundle_id & "|:65544}") & app_bindings)
my set_spaces_application_bindings(app_bindings)
end collect_application_in_current_space
on set_spaces_application_binding_for_application(application_bundle_id, chosen_space)
set application_bundle_id to my make_lowercase(application_bundle_id)
if chosen_space is in {0, "None"} then
my remove_spaces_application_binding(application_bundle_id)
else
if chosen_space = "All" then set chosen_space to 65544
my set_spaces_application_bindings((run script "{|" & application_bundle_id & "|: " & chosen_space & "}") & (my get_spaces_application_bindings()))
end if
end set_spaces_application_binding_for_application
on get_space_binding_for_application(application_bundle_id)
set application_bundle_id to my make_lowercase(application_bundle_id)
set app_bindings to my get_spaces_application_bindings()
try
get app_bindings as string
on error error_string
set app_bindings to my string_to_list(text 13 thru -20 of error_string, ", ")
end try
repeat with i from 1 to (count app_bindings)
if item i of app_bindings starts with ("|" & application_bundle_id & "|:") then return (item 2 of (my string_to_list(item i of app_bindings, ":"))) as number
end repeat
return 0
end get_space_binding_for_application
on choose_space_for_current_application()
return my choose_space_for_application(bundle identifier of (info for (path to frontmost application)))
end choose_space_for_current_application
on choose_space_for_application(application_bundle_id)
set application_bundle_id to my make_lowercase(application_bundle_id)
if (not my get_spaces_enabled()) then if (not my display_spaces_not_enabled_error()) then return false
try
tell application "Finder" to set app_path to (application file id application_bundle_id) as string
set app_name to short name of (info for (app_path as alias))
set the_choices to {"None", "All"}
repeat with i from 1 to (my get_spaces_count())
set end of the_choices to i
end repeat
set default_space to my get_space_binding_for_application(application_bundle_id)
if default_space = 0 then
set default_space to "None"
else if default_space = 65544 then
set default_space to "All"
end if
set chosen_space to (choose from list the_choices default items {default_space} with title "Spaces Assigner" with prompt "Assign " & app_name & " to Space:" OK button name "Assign" without multiple selections allowed and empty selection allowed)
if chosen_space = false then return false
my set_spaces_application_binding_for_application(application_bundle_id, item 1 of chosen_space)
return true
on error e number n
log "choose_space_for_application (" & application_bundle_id & ") Error (" & n & "): " & e
return false
end try
end choose_space_for_application
on remove_spaces_application_binding(application_bundle_id)
set application_bundle_id to my make_lowercase(application_bundle_id)
set app_bindings to my get_spaces_application_bindings()
try
get app_bindings as string
on error error_string
set app_bindings to my string_to_list(text 13 thru -20 of error_string, ", ")
end try
set new_bindings to {}
repeat with i in app_bindings
set i to contents of i
if i does not start with "|" & application_bundle_id & "|:" then set end of new_bindings to i
end repeat
my set_spaces_application_bindings(run script "{" & (my list_to_string(new_bindings, ", ")) & "}")
end remove_spaces_application_binding
on get_spaces_arrow_key_modifiers()
tell application "System Events" to tell spaces preferences of expose preferences to return (get key modifiers of (get properties of arrow key modifiers))
end get_spaces_arrow_key_modifiers
on get_spaces_numbers_key_modifiers()
tell application "System Events" to tell spaces preferences of expose preferences to return (get key modifiers of (get properties of numbers key modifiers))
end get_spaces_numbers_key_modifiers
on switch_to_space(space_number)
if not my gui_scripting_check() then return
set key_modifiers to my get_spaces_numbers_key_modifiers()
tell application "System Events"
set key_modifier_list to {}
if key_modifiers contains command then set end of key_modifier_list to "command down"
if key_modifiers contains control then set end of key_modifier_list to "control down"
if key_modifiers contains option then set end of key_modifier_list to "option down"
if key_modifiers contains shift then set end of key_modifier_list to "shift down"
set key_modifier_list to my list_to_string(key_modifier_list, ", ")
if key_modifier_list ≠ "" then set key_modifier_list to " using {" & key_modifier_list & "}"
end tell
run script ("tell application \"System Events\" to keystroke \"" & space_number & "\"" & key_modifier_list)
end switch_to_space
on open_spaces_preferences()
tell application "System Preferences"
activate
tell pane id "com.apple.preference.expose" to reveal anchor "Spaces"
end tell
end open_spaces_preferences
on display_spaces_not_enabled_error()
beep
activate
if ((button returned of (display dialog "Spaces is not enabled. Would You like to enable it now?" with title "Spaces Error" buttons {"Keep Disabled", "Enable"} default button 2 with icon 0)) = "Keep Disabled") then return false
my set_spaces_enabled(true)
return true
end display_spaces_not_enabled_error
on list_to_string(l, d)
tell (a reference to my text item delimiters)
set {o, contents} to {contents, d}
set {l, contents} to {"" & l, o}
end tell
return l as Unicode text
end list_to_string
on string_to_list(s, d)
tell (a reference to my text item delimiters)
set {o, contents} to {contents, d}
set {s, contents} to {s's text items, o}
end tell
return s
end string_to_list
on gui_scripting_check()
tell application "System Events" to set gui_scripting_enabled to UI elements enabled
if not gui_scripting_enabled then
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.universalaccess"
display dialog "This application utilizes the built-in Graphic User Interface Scripting architecture of Mac OS X which is currently disabled." & return & return & "You can activate GUI Scripting by selecting the checkbox \"Enable access for assistive devices\" in the Universal Access preference pane." with icon 2 buttons {"OK"} default button 1
end tell
end if
return gui_scripting_enabled
end gui_scripting_check
on make_lowercase(the_string)
return do shell script "echo " & quoted form of the_string & " | /usr/bin/perl -pe 'use encoding utf8; s/(\\w)/\\L$1/gi'"
end make_lowercase
You can use these to make your code :)
Link to the routines site :: MacScripter - Applescript Spaces Routine

Repeat function if variable is changed?

Having trouble figuring out this loop - I want the below function to repeat ONLY if myText changes (i.e. the album the individual is listening to changes) - I have been able to make it loop a certain number of times or repeat in the event the track changes, but I want it to repeat in the event the album changes.
tell application "iTunes"
repeat if myText changes
if player state is playing then
set albumName to (get album of current track)
set myText to text 1 thru 10 of albumName
end if
end repeat
end tell
open location "http://bandsite.com/shows/" & myText
When the code works without the repeat command it looks like this:
tell application "iTunes"
if player state is playing then
set albumName to (get album of current track)
set myText to text 1 thru 10 of albumName
end if
end tell
open location "http://bandsite.com/shows/" & myText
I need the whole function to repeat in the event myText changes
Save this as a stay open application:
property myList : {}
on run
set albumA to my playCheck()
if albumA ≠ false then
set end of myList to albumA
else
quit -- Quit on the next idle.
return 1 -- Please send the next idle as soon as possible.
end if
end run
on idle
set albumA to my playCheck()
if albumA ≠ false then
set end of myList to albumA
if (item -1 of myList) ≠ (item -2 of myList) then
open location "http://bandsite.com/shows/" & (text 1 thru 10 of albumA)
end if
end if
return 3
end idle
on playCheck()
tell application "iTunes"
if player state is playing then return (get album of current track)
return false
end tell
end playCheck
temptext = mytext
do
if temptext != myText
tell application "iTunes"
if player state is playing then
set albumName to (get album of current track)
set myText to text 1 thru 10 of albumName
end if
end tell
temptext = myText
end if
while temptext==text
Try this
Hope this is what you want...

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

Resources