Wednesday, September 30, 2020

#1 2020-08-12 01:55:11 am

olli
Member
Registered: 2008-11-01
Posts: 40

How to convert *applescript to *.scpt on the command line

In order to version control my applescripts I started to save them as text ('*applescript’). However to execute them it's better to have them avaivble as binary script ('*.scpt’).

Is there a command line tool I can use for this conversion? Or do i have to do it via Script Editor / Script Debugger?

The very best would be a background tool which watches the directory and converts changed applescript text files on the fly into binaries...

Last edited by olli (2020-08-12 01:55:36 am)


Filed under: CLI, binary, text-file, scpt

Offline

 

#2 2020-08-12 02:07:12 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6462

Re: How to convert *applescript to *.scpt on the command line

The command line tool is osacompile.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2020-08-12 02:19:58 am

olli
Member
Registered: 2008-11-01
Posts: 40

Re: How to convert *applescript to *.scpt on the command line

Thanks Shane! Will check it out.

Offline

 

#4 2020-08-12 07:44:50 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 620

Re: How to convert *applescript to *.scpt on the command line

FWIW, a while back Shane posted a ASObjC script that converts scpt to applescript. Perhaps this could be modified to convert in the other direction?

See Post 4 in

https://macscripter.net/viewtopic.php?id=47430


2018 Mac mini - macOS Catalina

Offline

 

#5 2020-08-12 08:31:38 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6462

Re: How to convert *applescript to *.scpt on the command line

peavine wrote:

Perhaps this could be modified to convert in the other direction?



You need to use OSAKit:

Applescript:

use AppleScript version "2.5" -- macOS 10.11 or later
use framework "Foundation"
use framework "OSAKit"
use scripting additions

set theFile to (choose file of type {"applescript"})
set aURL to current application's |NSURL|'s fileURLWithPath:(POSIX path of theFile)
set destinationURL to aURL's URLByDeletingPathExtension()'s URLByAppendingPathExtension:"scpt"
set {theScript, theError} to current application's OSAScript's alloc()'s initWithContentsOfURL:aURL |error|:(reference)
if theScript is missing value then error theError's |description|() as text
set {theResult, theError} to theScript's compileAndReturnError:(reference)
if theResult as boolean is false then return theError's |description|() as text
set {theResult, theError} to theScript's writeToURL:destinationURL ofType:"scpt" usingStorageOptions:0 |error|:(reference)
if theResult as boolean is false then return theError's |description|() as text


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#6 2020-08-12 08:59:19 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 620

Re: How to convert *applescript to *.scpt on the command line

Thanks Shane--that works great.


2018 Mac mini - macOS Catalina

Offline

 

#7 2020-08-12 06:54:38 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6462

Re: How to convert *applescript to *.scpt on the command line

I should add that you can change the storage option to 1 (OSAPreventGetSource) if you want run-only versions.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)