Hi Scripters,
I’m quite new to the Apple programming/scripting language as I had a Windows machine long time and used VB, VBA and VBS there.
Recently, I created a script, which starts 2 applications (Adium and Skype) simultaneously. The cause is simple: I have a Logitech Elite keyboard with exact one Messenger/SMS button and I wish to put this into use effectively, starting not one but all used IM applications (in the current situation 2).
Starting an application on its own is quite simple and I achieved it already. The tough part is now to get the windows hidden by closing them. Both applications support this without quitting and the commands I also already figured out. Giving enough delay after starting, this works fine. However, it is not exactly what I had in mind as the script runs for quite some time to give the applications enough time to start up even under busy conditions (letting it run too long under non-busy conditions).
As I experienced that, if an application is already open, the script is not opening the primary window by ‘re-launching’ it. Hence, the script runs into an error.
Trying further, I created not only a condition to verify, if the window exists, but also a loop to shorten the script runtime. So, the script retries every 5 seconds to close the windows putting in a variable that indicates, whether the script already closed the window of that application to provide the information if all windows have been closed to end the loop.
That, however, led into other issues: Not only does Skype obviously ‘emulate’ the open buddy window even as it is closed running through that condition and sets the variable without closing the window as it appears after the script comes to that line, I, as of now, fail to understand how to increase a variable in a loop to prevent the loop from running indefinitely*).
*) As either or even all applications are open, the main (buddy) windows are not opening, and hence the script is not running through the condition to close the windows and remains running.
After much explanation, this is the current state of the script:
global Adium, Skype, delaysecs, counter, countermax
set Adium to true
set Skype to true
set delaysecs to 5
set counter to 0
set countermax to 5
tell application "Finder"
launch application "Adium"
launch application "Skype"
end tell
repeat
if Adium is false and Skype is false then exit repeat
(* I wonder how to increase the below variable *)
(* counter = counter + 1 *)
display dialog "Counter: " & counter buttons {"Ok"} default button 1 (* Just checking the variable during debugging *)
if counter is greater than countermax then exit repeat
delay delaysecs
(* ========== Adium ========== *)
tell application "Adium"
if Adium then
if window "Contacts" exists then
close window "Contacts"
set Adium to false
end if
end if
end tell
(* =========================== *)
(* ========== Skype ========== *)
tell application "Skype"
if Skype then
if window "Skypeâ„¢ - Phoenix" exists then
close window "Skypeâ„¢ - Phoenix"
set Skype to false
end if
end if
end tell
(* =========================== *)
end repeat
If anyone has a hint on how to shorten the script runtime to do the necessary tasks (5 to be precise), while flawlessly executing them is much appreciated:
- Opening Adium
- Opening Skype
- Hiding Adium
- Hiding Skype
- End script after application windows are hidden (or at latest after the maximum repeat cycles have been run)
Regards,
Phoenix
Model: MacBook Pro
AppleScript: 1.10.7
Browser: Firefox 2.0.0.6
Operating System: Mac OS X (10.4)