Placeholders in Clippings, etc

I really like the feature in clippings where if “use scripted additions” or “use Library:LibraryName” are not already in a script, they get added when you place the clipping.

Is there a way to do the same thing with use AppleScript (with version)? (If not, can we request that?)

Also, I’m wondering if it would be possible to do that for variables or properties selected by the user?

In the sample below I have a group of variables that will be shared by the text in numerous clippings (those that build accessory views for Dialog Toolkit or Myriad Tables)

My strategy now is to note them out and delete them or unnote them as appropriate, but it would be really slick if they’d just not show up when I use the clipping.

[[*use "AppleScript version \"2.4\""]]
[[*usescriptingadditions]]
[[*library:Dialog Toolkit Plus]]

--Dialog variables
--set accViewWidth to 400
--set controlResults to {}
--set spacer to #~Number_or_Text~#
--set thisRow to spacer

→ Script Debugger 8.0.3 (8A49)
→ MacOS 11.6.2

Hello @estockly

I think you are pointing to “use Scripting Additions“ - right ?

There is no needs for reuesting that as a feature - you can allready use it but not like you did here:

here is an ASObjC Example with “AppKit” how I use this in SD Version 7.0.13 on my mid 2010 MBP 13" and it works:

[[*use AppleScript version "2.4"]] -- Yosemite (10.10) or later
[[*framework:Foundation]][[*framework:AppKit]][[*use scripting additions]]

It looks like this after insegrting:

Bildschirmfoto 2022-02-17 um 13.09.54

and so after compiling:

Bildschirmfoto 2022-02-17 um 13.10.21

based on my Example your Clipping should look like this if you want to get it all compiled:

[[*use AppleScript version "2.4"]] -- Yosemite (10.10) or later
[[*use scripting additions]]
[[*library:Dialog Toolkit Plus]]

--Dialog variables
set accViewWidth to 400
set controlResults to {}
set spacer to #~Number_or_Text~#
set thisRow to spacer

this should work just out of the box for you on your Mac.
I can’t test the compiling because I didn’t have installed Dialog Toolkit Plus yet.

that was an Example with predefined Variables…

now predefined properties…
There are two ways I know about and I try my very best to get all I know for now in here.

  • Properties which are autotically added by Script Debugger - for an Example what I am speaking of look for Shane’s Property List Clippings
  • Properties you can set for your own purpose - like Script Details you can display and use in your Error Message Dialogs.

Speaking of custom ones I for Example use the same thing Jim (@JMichaelTX) has used in his Scripts - like this:

property ptyScriptName : "[[template:SCRIPT_NAME_HERE]]"
property ptyScriptVer : "[[template:SCRIPT_VER(as digits)]]"
property ptyScriptDate : "[[template:SCRIPT_DATE]]"

You can use that approach in a clipping like so:

property ptyScriptName : "[[template:SCRIPT_NAME_HERE]]"
property ptyScriptVer : "[[template:SCRIPT_VER(as digits)]]"
property ptyScriptDate : "[[template:SCRIPT_DATE]]"


[[*use AppleScript version "2.4"]] -- Yosemite (10.10) or later
[[*use scripting additions]]

--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # Shane Stanleys "Dialog Toolkit Plus"
[[*library:Dialog Toolkit Plus]] version "[[template:LIB_VER]]"
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

-- Dialog variables
set accViewWidth to 400
set controlResults to {}
set spacer to #~Number_or_Text~#
set thisRow to spacer

[[selected-lines]]

Thats all I have for now…

Greetings from Germany

Tobias

Thank you Tobias, I was specifically referring to the “AppleScript Directives” described on the “How Clippings Work” page of Script Debugger help.

If your clipping has:
[[*usescriptingadditions]]
In that form, then if you paste it into a script that already has a “use scripting additions” statement, it won’t insert it a second time.

same is true for
[[*library:libraryname]]

This is particularly handy if you have multiple clippings that call various libraries and don’t want to duplicate those commands.

I was hoping for the same function with a use appleScript version clipping, where it would add the text at the top of the script only if there was not a copy already there.

While on that topic, there is a little typo in the help that threw me off for a bit.

On the “How Clippings Work” page

[[library:libraryvariable:libraryversion:libraryname]]

should be

[[*library:libraryvariable:libraryversion:libraryname]]

It took me a while to notice the “*” was missing.

So this text is now in every clipping that calls Dialog Toolkit:

[[*use AppleScript version "2.4"]] 
[[*usescriptingadditions]]
[[*library::1.2.3:Dialog Toolkit Plus]]

and when I use the clipping I get this:

use AppleScript version "2.4" 
use script "Dialog Toolkit Plus" version "1.2.3"
use scripting additions

If I paste a second clipping with that text this gets added:

use AppleScript version "2.4"

But the other two are not duplicated.

So, I guess I’ll remove the Use AppleScript call to avoid duplicates.

→ Script Debugger 8.0.3 (8A49)
→ Mac OS 11.6.3 (20G415)

Hey Ed

I’ve tested that back and forth but It does not work if you use SD7

If I use [[*usescriptingadditions]] in SD7 it gets iserted as “one word” and compiled as a Variable. That’s why I used [[*use scripting additions]].
SD7 will compile it as it is supposed to.

In my last example I gave you, you can see how I do my Script Definition Clippings. All of them have the [[*use scripting additions]] fully integrated so I don’t have to deal with it.
I even have it integrated In all my Custom Script Templates so this will not bother me to deal with “maybe I add that statement later”.

Maybe you should think about doing that in the same manner. The same for [[*use AppleScript version "2.x"]] Statements.

For [[*library:libraryname]] Statements I am thinking of in a similar way integrating them. But I also use to make a separate Clipping for each [[*library:libraryname]] Statement I will use - so that I can add a statement into my Script when additional Libraries are needed.

I think this is a simpler way of doing clippings like we are talking about here.

Greetings from Germany

Tobias

Interesting, I just tried [[*use scripting additions]] statement in SD7 and that works. And a second time doesn’t result in a duplicate. But using that version in SD8 does result in a duplicate if you use a second clipping.

[[*usescriptingadditions]] is how it’s in SD Help, and it’s probably a change from 7 to 8. (A change I highly recommend, BTW).

Yes, I have recently added

use AppleScript version "2.x"
use scripting additions

to the top of all my templates as well. But I have been doing this for a good number of years and have many older scripts that don’t have those that I often work on. It’s nice to get those added any time I use a clipping on an older script, and would be nicer if I didn’t duplicate the use AppleScript line. (I’m not sure how important that line is so I’m just not including it in the clippings).

Hey Ed

As far as I now it is necessary to have such a Statement like for Example use AppleScript version "2.3" if you are working with Scripting API’s like modifier flags because they are deprecated since Yosemite was released.

So if you for example talk to an API that is not awailable in El Capitan or Sierra but is one that came for example with High Sierra, - you probably guessed it - you have to use use AppleScript version "2.7"

long story short - the AppleScript version is your Key to the API’s you can use in your Scripts.

I would create a Clipping for each [[*use AppleScript version "2.x"]] Statement on it’s own whose you can add to existing Scripts depending on the API’s whose are used.

Greetings from Germany

Tobias

And of course thanks for pointing to that…

This helps me a lot since I also use SD8 on my 2019 iMac …

Tobias

1 Like