[SOLVED] Execute AppleScript question

When I use a local variable in the Execute AppleScript action I use this:

set kmInst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
	set myAppleScriptVar to getvariable "Local__myVar" instance kmInst
end tell

But in this case, since I'm just setting 1 variable, I can do this, right?

set kmInst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine" to set myAppleScriptVar to getvariable "Local__myVar" instance kmInst

adding the to before set and then removing end tell, right?

I would only use the first version if I'm setting 2 or more variables?

2 Likes

That is correct. :+1:t2:

Me personally, I try to use one-liners everywhere I can. The only time I don’t is when necessity warrants it (the tell block having more than one command for instance) or when a one-liner would be so long that reading it would be difficult due to it extended out of view.

1 Like

Thanks for checking and glad that this is the way to do it.

For this you could use that symbol to continue on the next line, right? I don't know what it's called or even how to add it, but I've seen it and I have some scripts that have them.
I also don't know if there are rules for them when it comes to where in the line you can add them or you can't.

Hello Tiago (@alltiagocom):wave:

I can’t remember the name of the said character either but a simple rule is that you can place it when ever there is a break from the standard syntax in AppleScript like the normal quotation if I remember it correctly… but be careful this rule may vary a lot if you embed shell commands with or without the quoted form of text concenating ….

You can also place it in front of the normal open bracket „(“

My advise is to use Script Debugger instead of Apple’s Script Editor … it has - if I remember it correctly - a feature build in to auto correct it if you make mistakes on using this character.

Even though in non paid version you will get far more power for developing AppleScript and AppleScript Objective-C code as with Script Editor. But I have Version 7 as paid Version and plan to buy version 8 as well. The 100$ it costs is worth every penny :smile::smile:

Greetings from Germany

Tobias

Press Option-Enter to create the line break symbol:

set kmInst to system attribute "KMINSTANCE"
tell application ¬
	"Keyboard Maestro Engine" to set myAppleScriptVar ¬
	to getvariable "Local__myVar" instance kmInst

-rob.

2 Likes

Thanks Rob (@griffman) :pray:

I always forget on how the character is created … and also a thank you for the snippet … it shows exactly what I was talking about in my reply…

Greetings from Germany

Tobias

Thank you for the shortcut and the name of the symbol.
Is there any rule to where you can or can't use it?

There are rules, but I don't recall what they are. If you try to put one in a spot it won't allow it to be used, though, I think it'll move it somewhere it can (maybe)? All I know for certain is that I've never broken a script by adding line break characters.

-rob.

Yes, @alltiagocom, in the spirit of @cdthomer's one-liners and @griffman's line break method, you could use:

tell application ¬
	"Keyboard Maestro Engine" ¬
to set myAppleScriptVar to getvariable "Local__myVar" ¬
instance system attribute "KMINSTANCE"

That is, the...

set kmInst to system attribute "KMINSTANCE"

... can be rolled into the one-liner.

1 Like