Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Applescript Variable for an Application

Applescript Variable for an Application
Thread Tools
izpinoza17
Fresh-Faced Recruit
Join Date: Mar 2008
Status: Offline
Mar 24, 2008 , 01:19 PM
 
Hello,
I am trying to write a script where I run multiple instances of Safari (Safari 1, Safari 2 etc.) and I want to be able to refer to the one I am currently working with (the active one) as active_Safari (so for example set active_Safari to "Safari 1"). The problem is that I always get an error when I try to put down the variable instead of the usual way to refer to an application. Here is my script below:

When I run this, I always get this error, and I don't get it when I replace the variable with "Safari 1"...is it not possible to use variables as placeholders for applications?

System Events got an error: Can't get application "Safari 1".

on Change_active_Safari(num)
return "Safari " & (num as string)
end Change_active_Safari

set active_Safari to Change_active_Safari(1)

--following code checks if Safari 1 has loaded its page
delay 0.5
tell application "System Events" to tell application (active_Safari as string)
activate
if (name of window 1) begins with "Contacting" or (name of window 1) begins with "Loading" then
else
--tell application "Extra Suites" to say "done"
end if
end tell

(*
When I run this, I get:
System Events got an error: Can't get application "Safari 1".
But if I replace active_Safari variable with the name of the app itsel ("Safari 1") I get no error.
*)
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:17 AM.
All contents of these forums © 1995-2008 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.6.8 © 2000-2008, Jelsoft Enterprises Ltd., SEO by vBSEO 3.0.0 RC8