[OSAX]AppleScript Toolbox

I have not really an idea where to post this on MS so I guess Code Exchange is close enough.

[color=red]UPDATE 2017-07-23: AppleScript Toolbox 2.0.8[/color]
AppleScript Toolbox 2.0.x

See the release notes for recent changes

I will begin with a thank you. I want to thank Nigel Garvey for his time testing, writing and advices while developing this osax version. Without his help, the interface of the osax would have been messy and it would have contain definitely some (more) bugs.

AppleScript Toolbox 2.0.x (AST) is new but with the “same” commands. The main differences are AST internals that have been renewed, polished and sometimes completely rewritten. While AST version 1.x was an project in development, AST 2.0 is not. AST internals will keep working as it is and next improvements/extending the set of commands will be build upon this.

To read more about the commands read the dictionary of the osax. Here a summary of all the commands.

[b]AST version[/b] “ return the version of the currently loaded AST osax.
[b]AST list processes[/b] “ return the processes running on your system.
[b]AST list folder[/b] “ return the items of a given folder.
[b]AST list volumes[/b] “ return the currently mounted volumes.
[b]AST query metadata[/b] “ Query the metadata database of the system.
[b]AST metadata for file[/b] “ return all available metadata of the given file.
[b]AST application for file[/b] “ return path to file handler.
[b]AST click[/b] “ click the mouse.
[b]AST mouse point location[/b] “ return the current location of the mouse.
[b]AST set mouse point location[/b] “ move the mouse to the given location.
[b]AST format date[/b] “ return the date as string in format.
[b]AST date with format[/b] -- return the date from a string using format
[b]AST copy string[/b] “ make a copy of the string while applying actions.
[b]AST find regex[/b] “ apply regular expression to string.
[b]AST guess language for[/b] “ guess the language of the given string.
[b]AST levenshtein distance[/b] “ the distance between two string.
[b]AST copy list[/b] “ make a copy of the list and apply certain actions to it.
[b]AST base64 encode[/b] “ encode a string into n base64 encoded string.
[b]AST base64 decode[/b] “ decode a base64 encoded string into a string.
[b]AST URL encode[/b] “ encode a string into n URL encoded string.
[b]AST URL decode[/b] “ decode a URL encoded string into a string.

The OSAX can be downloaded here.
All links to AST 1.x versions have been removed in this topic as on the astoolbox.wordpress.com because it is not recommended to continue to use.

Thanks for this, much appreciated!

Hey DJ,

Nice!

I’ll play with it later today.

I’ve really been wanting to do something like this myself, but I’ve never taken the time.

Good show.

Yeah. :slight_smile:

I really like how you have engineered the namespace for it, to minimize collisions, I also like the way the list events returns copies of the lists. :slight_smile:

By the way, here is a paper by Alan Kay: The Early History of Smalltalk

That’s now:

AST click at {20, 20}

Thank you all for the nice responses.

p.s. I’ve updated the example code Nigel, thanks for the update.

Thanks,
How Can I use AST with a shell ? (osascript)

Must I add the full path to “AppleScript Toolbox.osax” ?

path in my TestApp is:

/Volumes/Axel_1/RealStudio/AS_ScriptAdditions/ASAdd.debug.app/Contents/Resources/ScriptingAdditions/AppleScript Toolbox.osax

When this scripting addition is installed in ~/Library/ScriptingAdditions/, /Library/ScriptingAdditions, /System/Library/ScriptingAdditions (not recommended) or in in a network library, the scripting addition can be use on the command line using osascript. When a command from AppleScript Toolbox is used, the scripting addition is loaded automatically.

If you want the osax to be embedded inside your application, yes, you need to install it inside the application bundle as you described.

Thanks, but I do not know where to insert the path

for example, if AST is in User Library Folder I can use

/usr/bin/osascript -e ‘AST set mouse point location {50, 66}’ in Terminal

Where should I insert the path from the app ?

The first update by requests/advice from users. The update affects the AST copy list command and has changed a few things. First is that it’s not longer possible to choose between different sort algorithms. The required overhead for different sort methods is too large to notice any difference in the performance. Also the purpose of keeping this AppleScript-plugin as easy as possible is quite in conflict when the user will be bothered with different kind of sorting algorithms.

One of the new features is that the sorting criteria can be changed by the following parameters:

[b]case sensitivity[/b] “ [i]is the order case sensitive?[/i]
[b]diacritic sensitivity[/b] “ [i]is "ü" the same as "u"?[/i]
[b]numeric sorting[/b] “ [i]does "file name 10.txt" has to be sorted after "file name 2.txt"?[/i]

Another new feature is the boolean parameter keeping duplicates. When this parameter is set to false duplicates are removed from the list. The parameters case sensitivity and diacritic sensitivity are taken into consideration to determine if two strings from the list are the same. Important to know is that when an item in the list is not a string, the comparison is made by the AE.framework so sublists containing strings of the given list are handled differently that strings inside the given list.

update
Links to older versions are removed

Just to be sure that we understand eachother: Do you want this osax to be embedded in your application, and use it with an osascript shell command?

I’m not sure if that is even possible because you have no control over where the OpenScripting.framework will search for when loading osaxen. The OpenScripting.framework will first ask for the main bundle, which can be the currently application and find the embedded osax in there. When you run from the command line using osascript, the current application, has become another process and it will find not an embedded file.

The proper way of sorting this out is looking if the osax is installed in either /Library/ScriptingAdditions or ~/Library/ScriptingAdditions. When it’s not installed you will prompt the user for a user name and password and copy the osaxen to either one of these folders. Even if the authorization is not required for the user home folder, it’s better that the user will be notified that something will be installed into his system. When you have finished this you can use the osascript command line again.

However, as always, there is a dirty trick. When I need to debug my osaxen I don’t want to install the scripting addition every time, or sometimes I want to launch Script Editor with a specific osaxen outside the standard ScriptingAddition folder locations (on my desktop for instance). While this should only be used for debugging you can use this for osascript as well. If you set the environment variable DYLD_FRAMEWORK_PATH before using osascript, you tell the OpenScripting.framework where to look for osaxen. so in your case you’ll need:

set OSAXPath to "/Volumes/Axel_1/RealStudio/AS_ScriptAdditions/ASAdd.debug.app/Contents/Resources/ScriptingAdditions"
do shell script "export DYLD_FRAMEWORK_PATH=" & quoted form of OSAXPath & "
/usr/bin/osascript -e 'AST set mouse point location {50, 66}'"

update: Links to old versions of AST has been removed.
AST has two new commands and AST find regex is updated with a new parameter

¢ AST list processes “ It's already possible to list processes with System Events but only processes connected to the window server are listed. The command will list every BSD process running on your system.
¢ AST application for file “ This is a new command that uses launch services to indicate the path to which application will used to handle the file
¢ AST find regex “ this command is updated with a new parameter returning all groups, where the first item is the entire match. This option will return all groups of the regular expression where each sublist equals a match.
set theData to "http://www.macscripter.net/viewtopic.php?pid=181361#p181361"

set theAtoms to AST find regex "(http){1}://([^/]+)(/[^?]*)\\?([^#]+)#?(.*)?" in string theData with returning all groups
set {theLink, theScheme, theServer, thePath, theQuery, theAnchor} to item 1 of theAtoms

Version 2.0 is now released, see first post.

Don’t know how many others have this problem, but when I click on any of the links I get a “We’re sorry, you don’t have access to this page.” return from Google.

Sorry Adam, it should be working again.

It is. Thanks.

Interesting:

AST metadata for file () crashes Script Debugger if I put in a file path or alias to a file, but works perfectly if I put in choose file.

Script Debugger’s problem, no doubt. I reported it.

Seems like an system error. When using a file that is not indexed or damaged in the metadatabase, script editor unexptectedly quits. When I type in the terminal ‘mdls /’ I do get the same error. I have build an version 2.0.1 which just omits this error and return an empty list instead.

Small announcement,

Version 2.0.6 of AST is build against the 10.12 (Sierra) SDK and with a new feature in the AST copy list command, sorting 2D lists.