Basic questions: "Return" character/referencing other scripts/more

Hi -

Let me begin by saying I’m learning quite a bit from the experienced developers on this forum. You are all great teachers, demonstrating the power of AppleScript by example after example and it is an incredible resource for someone like me – an experienced developer with skills that are very strong in a totally different type of “programming” (my specialty is optimizing SQL for faster – preferably sub second – execution). I have several of the recommend books on the way and I’ve been reading the excellent guides linked to here. Again - I profusely thank everyone who has taken the time to aid anyone learning because you helped not just that person, but everyone who came along later (like me).

There are some basics that I can’t find in a simple FAQ – so I thought I’d ask here and post a summary in several of my blogs that are most visited along with a link to the posts here that provide the details.

  1. That little character that looks like a “Return” symbol - what is that and why is it used?
  2. I found the great sample libraries here http://applescript.bratis-lover.net/library/ and I’m wondering if there is a more effective way to reference script libraries. The examples provided there count on the scpt files being in specific locations. Is there a “path” nomenclature for scripts where I can store libraries that would work consistently when deploying a packaged script to a client or should I just include the script libraries (like the string manipulation one) in the local folder that the script I write will live in, which in my case would be ~/Library/Application Scripts/com.apple.mail ?
  3. With your vast experience, are there reasons you’d avoid AppleScript in favor of Perl or Ruby to do small amounts of string manipulation (as they are definitely faster for handling strings in many cases)?

Thanks again for everything - I’m so thrilled to have been accepted to this community and I promise to do more searching, less posting of questions so you folks aren’t repeating yourselves on the basics over and over. I see already I have a lot of reading to do!

All the best,
Christopher
:slight_smile:

Model: MacBookPro13,3
Browser: Safari 602.2.14
Operating System: Mac OS X (10.10)

Hi Christopher.

The only symbol I can think of that you might mean is the line continuation character (¬), which you can get by typing option-l (lower case L). In Script Editor, you can also type option-return to get this character immediately followed by a return. Its only function is to break up a line in the source code so that the parts take up less horizontal space or are perhaps divided into discrete clauses for easier reading. Its use is entirely optional and the compiler might move it to a different position if it sees fit.

set myList to {¬
	1, 2, 3, 4, 5, ¬
	6, 7, 8, 9, 10}
-- Same as:
set myList to {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

if (2 = 2) or ¬
	deathIsCertain or ¬
	pigsCanFly then ¬
	beep
-- Same as:
if (2 = 2) or deathIsCertain or pigsCanFly then beep

The preferred library location since Mac OS 10.9 is a folder called “Script Libraries” (which you may have to create yourself) in any of the locations described here:

https://developer.apple.com/library/content/documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_script_objects.html#//apple_ref/doc/uid/TP40000983-CH207-SW6

With this system, you put ‘use script’ at the top of the main script with just the name of the library script (leaving out the “.scpt” or “.scptd” extension. The main script will locate the library itself. Obviously if there’s another script with the same name in a higher priority location, that will be loaded instead.

use script "My Library Script" -- At the top of the script.

The older system with ‘load script’ can still be used and is described here:

https://developer.apple.com/library/content/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_load_script.html#//apple_ref/doc/uid/TP40000983-CH227-SW1

This does require a full specifier for the library script. In this case, the library script doesn’t need to be in one of the “Script Libraries” locations, but it’s a good idea to use one anyway for compatibility between the two systems.

A script in the user’s “Script Libraries” location can be specified as:

((path to library folder from user domain as text) & "Script Libraries:My Library Script.scpt") as «class furl»

‘path to me’ and ‘path to resource’ offer various possibilities for locations relative to the main script file’s location, but the newer ‘use’ system’s easier to ” er ” use.

It depends. If you’re using AppleScript anyway, it can usually perform simple string manipulations itself faster than it can tell other processes to do them, although it doesn’t do regex. On the other hand, if you’re a world expert in Perl or Ruby or some other language and aren’t so familiar with AppleScript, you may feel more comfortable using them instead ” which is possible from AppleScript. There are also third party OSAXen such as Satimage or AppleScript Toolbox which have some pretty powerful and fast text handling capabilities.

I should perhaps add that to assign the library script to a variable (say ‘myLib’ ) for use in the main script, the ‘use’ syntax would be .

use myLib : script "My Library Script"

. and with ‘load script’ .

set myLib to (load script (((path to library folder from user domain as text) & "Script Libraries:My Library Script.scpt") as «class furl»))

-- Or with fewer parentheses:
set myLib to (load script alias ((path to library folder from user domain as text) & "Script Libraries:My Library Script.scpt"))

Thanks for the help with these basic concepts!

Best regards,
Chris