Tuesday, March 28, 2017

#1 2015-05-22 11:10:26 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2590

[OSAX]AppleScript Toolbox

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

UPDATE 2016-10-4: AppleScript Toolbox 2.0.7
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.

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

Last edited by DJ Bazzie Wazzie (2016-10-06 03:45:21 am)

Offline

 

#2 2015-05-22 11:44:14 am

kerflooey
Member
Registered: 2011-07-07
Posts: 113

Re: [OSAX]AppleScript Toolbox

Thanks for this, much appreciated!

Offline

 

#3 2015-05-23 01:20:41 am

ccstone
Member
Registered: 2009-02-07
Posts: 403

Re: [OSAX]AppleScript Toolbox

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.

Offline

 

#4 2015-05-23 03:54:03 am

McUsrII
Member
Registered: 2012-11-20
Posts: 3046
Website

Re: [OSAX]AppleScript Toolbox

Yeah. 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. smile

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

Last edited by McUsrII (2015-05-23 04:11:58 am)

Offline

 

#5 2015-05-23 05:26:24 am

Nigel Garvey
Moderator
From: Warwickshire, England
Registered: 2002-11-19
Posts: 4223

Re: [OSAX]AppleScript Toolbox

DJ Bazzie Wazzie wrote:

click Apple-menu

Applescript:

AST click {20, 20}

That's now:

Applescript:

AST click at {20, 20}


NG

Offline

 

#6 2015-05-23 03:32:49 pm

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2590

Re: [OSAX]AppleScript Toolbox

Thank you all for the nice responses.

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

Offline

 

#7 2015-05-23 06:52:32 pm

axel99092
Member
From: Erfurt / Germany
Registered: 2014-02-12
Posts: 20
Website

Re: [OSAX]AppleScript Toolbox

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

Offline

 

#8 2015-05-23 07:20:02 pm

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2590

Re: [OSAX]AppleScript Toolbox

axel99092 wrote:

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

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.


axel99092 wrote:

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

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

Offline

 

#9 2015-05-23 09:15:34 pm

axel99092
Member
From: Erfurt / Germany
Registered: 2014-02-12
Posts: 20
Website

Re: [OSAX]AppleScript Toolbox

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 ?

Offline

 

#10 2015-05-28 11:40:28 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2590

Re: [OSAX]AppleScript Toolbox

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:

    case sensitivityis the order case sensitive?
    diacritic sensitivityis “ü” the same as “u”?
    numeric sortingdoes “file name 10.txt” has to be sorted after “file name 2.txt”?

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

Last edited by DJ Bazzie Wazzie (2016-01-11 09:02:38 am)

Offline

 

#11 2015-06-10 08:08:22 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2590

Re: [OSAX]AppleScript Toolbox

axel99092 wrote:

Where should I insert the path from the app ?

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:

Applescript:

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}'"

Offline

 

#12 2015-07-27 02:51:08 pm

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2590

Re: [OSAX]AppleScript Toolbox

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.



Applescript:

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

Last edited by DJ Bazzie Wazzie (2016-01-11 09:05:41 am)

Offline

 

#13 2016-01-11 09:08:12 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2590

Re: [OSAX]AppleScript Toolbox

Version 2.0 is now released, see first post.

Offline

 

#14 2016-01-14 09:18:28 am

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4656

Re: [OSAX]AppleScript Toolbox

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.


iMac running OS X 10.11.6

Offline

 

#15 2016-01-14 09:36:21 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2590

Re: [OSAX]AppleScript Toolbox

Adam Bell wrote:

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.

Offline

 

#16 2016-01-14 10:52:54 am

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4656

Re: [OSAX]AppleScript Toolbox

It is. Thanks.


iMac running OS X 10.11.6

Offline

 

#17 2016-01-14 12:06:49 pm

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4656

Re: [OSAX]AppleScript Toolbox

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.


iMac running OS X 10.11.6

Offline

 

#18 2016-01-14 01:28:15 pm

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2590

Re: [OSAX]AppleScript Toolbox

Adam Bell wrote:

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.

Last edited by DJ Bazzie Wazzie (2016-04-11 06:10:26 am)

Offline

 

#19 2016-09-30 09:21:05 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2590

Re: [OSAX]AppleScript Toolbox

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.

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.098 seconds, 11 queries executed ]

RSS (new topics) RSS (active topics)