Hello! Dilemma with variable application syntax!

Hi! I’m working on a great program to keep my dial internet connection alive and my download program going between certain hours. My problem is i would like to be able to control different download apps. Here’s what i’m working with:


property apptoopen:""
property shortappname : ""

-- click button to get apptoopen as alias in this example "Clock.app"
set filer to name of (info for apptoopen)
set text item delimiters to "."
set shortappname to first text item of filer as string  -- so far so good... this gives me "Clock"
set theprocess to name of every process as list
if theprocess does not contain shortappname then     -- if "Clock" is not in the running processes - works
     tell application shortappname  --  Here's my problem. I don't know if it needs double quotes or backslashes or
           do whatever                    -- what, but if you replace shortappname with "Clock" it works fine. I need it to be
     end tell                                  -- variable.
end if
-- I could open the app with finder, as:
tell application "Finder" open apptoopen
--to launch it, but i still need to be able to quit it. any help would be much appreciated.

10.2.8
Applescript Studio Project Builder 2.0.1

also, is there any way for my script to see if the phone is ringing or in use? Internet connect doesn’t recognize if the phone is ringing, just gives you an error. Suggestions on a third party solution?

nevermind, couldn’t call a variable app under the
tell application “system events”
handler.
all better.

I have a similar question:

Why can’t I seem to use a variable to store the name of an application, then use the variable at the end of “using terms from application” line? Here’s my example, from a full project where a key pair is set in the user defaults file, the key pair is read and set as a variable, then the variable is used:

– in the startup script…

on will finish launching theObject
	make new default entry at end of default entries of user defaults with properties ¬
		{name:"primaryApp", contents:"<some program you want to talk to>"}
	set targetApp to contents of default entry "primaryApp" of user defaults
	log targetApp -- just to make sure it happened, and the variable dies at the end of this script anyway.
end will finish launching

The log points always check out correct.
– then, in the script that’s run by a button…

on clicked theObject
	set targetApp to contents of default entry "primaryApp" of user defaults
	-- set targetApp to (targetApp as string) Do I need something like this? I don't think I do...
	log targetApp -- just to make sure it was read and set right...

	using terms from application targetApp
		tell application targetApp of machine targetMac
			Event "<some event that targetApp recognizes>"
		end tell
	end using terms from
end clicked

The log points always check out correct here too.
Here’s the problem - the script won’t even compile! The error comes at the use of targetApp in the “using terms from” line, and the error is the dreaded and very not understood on my part “Syntax Error: Can’t make some data into the expected type.”

I’ve only this morning overcome the inability to use a variable to call out the remote machine, and also overcome my inability to use a variable for the application to talk to. Those problems were solved for me by using “using terms from” and NOW that’s not letting me use a variable either!

Can some kind sould explain to me if and how I need to somehow change the variable’s type, or use some sort of “delimiter” statement or something to get “using terms from” to use the darn thing?

Believe it or not there’s a reason why in this project I need to implement a preferences kind of thing where the user would set talking to a local copy of one or the other of two related applications, or one or the other of the same applications running on a remote machine where the two applications work with the same external events. It’s a very specific in-house application.

As always, thank you in advance.

Cheers,

WM

By the way, this is related to my questions posed in the thread http://bbs.applescript.net/viewtopic.php?id=15697

Cheers,

WM

Hi.

‘using terms from’ is an instruction to the compiler to query the application concerned for the code to compile into the script. A variable like ‘targetApp’ won’t be set until the script’s actually run, so it’s no good at compile time.

‘tell application’ is similar in that it tells the compiler where to look for information about how to compile the script text. If an explicit name’s used, the compiler gets the information from that specific application. If a variable’s used, as in pilothigh’s script, the compiler doesn’t have that information to hand and can only compile AppleScript language keywords, OSAX keywords, and a few generic application commands such as ‘activate’ and ‘quit’.

At run time, ‘tell’ also ensures that generic commands get sent to the targeted applications, whereas ‘using terms from’ has no run-time function. It’s sole purpose is to guide the compiler when the ‘tell’ line can’t do it for some reason. You’d normally use it in cases where the user’s version of an application might not have the same name as the version on the machine where the script’s compiled. (For instance, some apps have version numbers in their names.)

Never even used the “Using terms from” tag. I had to pick the worst time in the world to try and learn applescript. Apparently I joined the scriptarmy during times of upheavel and massive change. From OS 10.2 - 10.4 I’ve counted at least thirty terms that my computer (10.2.8) refuses to compile in any form. And from the many problems I’ve seen here, I assume that it works the other way around. My program, written with 10.2, probably won’t even load on 10.4. Many posts here i can’t even reply to for fear I’ll confuse their computer with my antique script syntax :slight_smile: