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
Related
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
this code almost works. :) Basically I am trying to zip a file and then attach that email to a new mail message.
The process starts in automator and then the script runs. Everything works except the actual attaching of the file.
My knowledge of AppleScript is pretty limited but trying to wrap my head around this. I combined to different code snippets to get this far.
on run {input, parameters}
set display_text to "Please enter your password:"
repeat
considering case
set init_pass to text returned of (display dialog display_text default answer "" with hidden answer)
set final_pass to text returned of (display dialog "Please verify your password below." buttons {"OK"} default button 1 default answer "" with hidden answer)
if (final_pass = init_pass) then
exit repeat
else
set display_text to "Mismatching passwords, please try again"
end if
end considering
end repeat
tell application "Finder"
set theItems to selection
set theItem to (item 1 of input) as alias
set itemPath to quoted form of POSIX path of theItem
set fileName to name of theItem
set theFolder to POSIX path of (container of theItem as alias)
set zipFile to quoted form of (fileName & ".zip")
do shell script "cd '" & theFolder & "'; zip -x .DS_Store -r0 -P '" & final_pass & "' " & zipFile & " ./'" & fileName & "'"
end tell
tell application "Finder"
#I believe this is where the problem is, I am trying to use the variables from above in order to attach the file in mail.
set folderPath to theFolder
set theFile to zipFile
set fileName to zipFile
end tell
set theSubject to fileName
set theBody to "Hello sir. Here is my " & fileName
set theAddress to "Some Email"
set theAttachment to theFile
set theSender to "Some Sender"
tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return, visible:true}
tell theNewMessage
set visibile to true
set sender to theSender
make new to recipient at end of to recipients with properties {address:theAddress}
try
make new attachment with properties {file name:theAttachment} at after the last word of the last paragraph
set message_attachment to 0
on error errmess -- oops
log errmess -- log the error
set message_attachment to 1
end try
log "message_attachment = " & message_attachment
#send
end tell
end tell
return input
end run
I've fixed up most of the things that are off with your code. The following works in an automator Run AppleScript action if you pass in a list containing an alias to a file:
on run {input, parameters}
set display_text to "Please enter your password:"
repeat
considering case
set init_pass to text returned of (display dialog display_text default answer "" with hidden answer)
set final_pass to text returned of (display dialog "Please verify your password below." buttons {"OK"} default button 1 default answer "" with hidden answer)
if (final_pass = init_pass) then
exit repeat
else
set display_text to "Mismatching passwords, please try again"
end if
end considering
end repeat
tell application "System Events"
set selected_file to item 1 of input
set selected_file_name to name of selected_file
set containing_folder_path to POSIX path of (container of selected_file) & "/"
set zip_file_path to containing_folder_path & selected_file_name & ".zip"
do shell script "cd " & quoted form of containing_folder_path & "; zip -x .DS_Store -r0 -P " & quoted form of final_pass & " " & quoted form of zip_file_path & " " & quoted form of selected_file_name
set zip_file_alias to file zip_file_path as alias
end tell
set theSubject to selected_file_name
set theBody to "Hello sir. Here is my " & selected_file_name
set theAddress to "Some Email"
set theSender to "Some Sender"
tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return, visible:true}
tell theNewMessage
set visibile to true
set sender to theSender
make new to recipient at end of to recipients with properties {address:theAddress}
try
make new attachment with properties {file name:zip_file_alias} at end of attachments
on error errmess -- oops
log errmess -- log the error
end try
log "message attachment count = " & (count of attachments)
#send
end tell
end tell
return input
end run
Highlights:
I switched from using the Finder to using System Events. Avoid using the Finder unless you absolutely need to (it's a very busy app)
I set the name property of the attachment to an alias to the compressed file the script creates
I cleaned up this and that to make things clearer.
Here is what I ultimately came up with, which worked but the file handling for the attachment still needed work.
on run {input, parameters}
tell application "Finder"
set theItem to (item 1 of input) as alias
set theItemCopy to theItem
set itemPath to quoted form of POSIX path of theItem
set fileName to name of theItem
set theFolder to POSIX path of (container of theItem as alias)
set zipFile to quoted form of (fileName & ".zip")
set setPass to "Password" #test password
do shell script "cd '" & theFolder & "'; zip -x .DS_Store -r0 -P '" & setPass & "' " & zipFile & " ./'" & fileName & "'"
end tell
tell application "Mail"
set fileLocation to (fileName & ".zip")
set theSubject to "Subject" -- the subject
set theContent to "Attached are the documents from the last session." -- the content
set theAddress to "email#email.com" -- the receiver
set theAttachmentFile to "Macintosh HD:Users:dave:desktop:" & fileLocation -- the attachment path
set msg to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
delay 1
tell msg to make new to recipient at end of every to recipient with properties {address:theAddress}
tell msg to make new attachment with properties {file name:theAttachmentFile as alias}
end tell
return input
end run
I feel it should be a simple task, but I could not find a solution yet. Basically, I want to clean up the items of the desktop using Applescript, the same way I would by right-clicking the desktop and clicking "Clean up".
Unfortunately, something like the following does not work:
tell application "Finder" to clean up desktop
Any ideas?
This is what I use:
set theFiles to {}
set folderExtensions to {}
set _extensions to {}
tell application "Finder" to set theFiles to every file in folder (desktop as string)
tell application "Finder"
if not (folder ((desktop as string) & "Mydesktop") exists) then
make folder at (desktop as string) with properties {name:"Mydesktop"}
end if
end tell
set i to 0
repeat (number of items in theFiles) times
set i to i + 1
set _extensions to _extensions & (name extension of (info for file ((item i of theFiles) as string)))
end repeat
set i to 0
repeat (number of items in _extensions) times
set i to i + 1
if folderExtensions does not contain (item i of _extensions) then
set folderExtensions to folderExtensions & (item i of _extensions)
end if
end repeat
set i to 0
repeat (number of items in folderExtensions) times
set i to i + 1
tell application "Finder"
if not (folder ((desktop as string) & "Mydesktop:" & (item i of folderExtensions)) exists) then
make folder at ((desktop as string) & "Mydesktop:") with properties {name:(item i of folderExtensions)}
end if
end tell
end repeat
set i to 0 ------we are moving the files now
set _key to ""
set x to 1
set letters to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
repeat
set x to x + 1
if x > 100 then return
set _key to ""
repeat 20 times
set _key to _key & (item (random number from 1 to 26) of letters)
end repeat
tell application "Finder"
if not (folder ((desktop as string) & "Mydesktop:" & _key) exists) then
make folder at folder ((desktop as string) & "Mydesktop:") with properties {name:_key}
exit repeat
end if
end tell
end repeat
repeat (number of items in theFiles) times
set i to i + 1
tell application "Finder"
if not (file ((desktop as string) & "Mydesktop:" & (item i of _extensions) & ":" & (name of (info for file ((item i of theFiles) as string)))) exists)
then
move file ((item i of theFiles) as string) to folder ((desktop as string) & "Mydesktop:" & (item i of _extensions) & ":")
else
set x to 1
repeat
set x to x + 1
if x > 100 then exit repeat
if not (file ((desktop as string) & "Mydesktop:" & (item i of _extensions) & ":" & (name of (info for file ((item i of theFiles) as string))) & " " & x) exists) then
set someItem to (item i of theFiles)
tell application "System Events" to tell disk item (someItem as text) to set {theName, theExtension} to {name, name extension}
if theExtension is not "" then set theName to text 1 thru -((count theExtension) + 2) of theName -- the name part
set old to ((desktop as string) & "Mydesktop:" & _key & ":" & (name of (info for file ((item i of theFiles) as string))))
move file ((item i of theFiles) as string) to folder ((desktop as string) & "Mydesktop:" & _key & ":")
set the name of file old to theName & " " & x & "." & theExtension
move file ((desktop as string) & "Mydesktop:" & _key & ":" & theName & " " & x & "." & theExtension) to folder ((desktop as string) & "Mydesktop:" & (item i of _extensions) & ":")
exit repeat
end if
end repeat
end if
end tell
end repeat
set item1 to (the quoted form of POSIX path of ((((path to desktop) as string) & "Mydesktop:" & _key) as alias))
set deleteit to "rm -rf " & item1 & ""
try
do shell script deleteit
on error
do shell script deleteit with administrator privileges
end try
It creates a folder (if it does not already exist) and sorts all my files.I have exported it as an application and have set it to open every time I log in!That way I start with a nice clean desktop.
This seems to work for me:
tell application "System Events"
tell application "Finder"
activate desktop
end tell
-- this delay is to ensure that the second block of code doesnt run too fast, or it will not work, if this doesn't work, try increasing this delay
delay 0.1
tell process "Finder"
-- this clicks the the clean up button from the menu bar at the top, the "activate desktop" at the beginning was to make sure that the desktop's menu bar was the front menu bar
click menu item "Clean Up" of menu "View" of menu bar item "View" of front menu bar
end tell
end tell
Edit: new improved script
tell application "System Events"
-- hides everything, which makes the menu bar become the desktop's menu bar
set visible of every process to false
set visible of process "Finder" to false
end tell
delay 0.1
tell application "System Events"
tell process "Finder"
click menu item "Clean Up" of menu "View" of menu bar item "View" of front menu bar
end tell
end tell
I am trying to achieve some automation in my current workflow. I'd like to drop images to my applescript application, then have it autoresize to the size as set by the user.
I prompt the user a dialog, where one can enter the pixelsize for width, then have the script do the donkey work.
For some reason it is not running properly, and for the life of my i can't figure out why.
Any and all help is very much appreciated!
Here's the script:
display dialog "What is the desired size?" default answer "64"
set my_answer to text returned of result
on open some_items
repeat with this_item in some_items
try
rescale_and_save(this_item)
end try
end repeat
end open
to rescale_and_save(this_item)
tell application "Image Events"
launch
set the target_width to my_answer
-- open the image file
set this_image to open this_item
set typ to this_image's file type
copy dimensions of this_image to {current_width, current_height}
if current_width is greater than current_height then
scale this_image to size target_width
else
-- figure out new height
-- y2 = (y1 * x2) / x1
set the new_height to (current_height * target_width) / current_width
scale this_image to size new_height
end if
tell application "Finder" to set new_item to ¬
(container of this_item as string) & "scaled." & (name of this_item)
save this_image in new_item as typ
end tell
end rescale_and_save
I wrote this script a while ago. It will re-sample an image so its largest dimension is the input value.
on open of myFiles
set my_answer to text returned of (display dialog "What is the desired size?" default answer "64")
repeat with aFile in myFiles
set filePath to aFile's POSIX path
set bPath to (do shell script "dirname " & quoted form of filePath)
tell application "System Events" to set {fileName, fileExt} to {name, name extension} of aFile
set baseName to text 1 thru ((get offset of "." & fileExt in fileName) - 1) of fileName
do shell script "sips " & quoted form of aFile's POSIX path & " -Z " & my_answer & " --out " & quoted form of (bPath & "/" & baseName & "-" & my_answer & "." & fileExt as text)
end repeat
end open
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