1

I'm trying to write several AppleScript scripts that share common functions. Ideally, they would include a separate file where these functions are defined.

Since this will be in a repository instead of locked to a particular machine, I can't rely on the script library directory to do it. I'm trying to load a script from a relative path.

But none of it seems to work. At first, I thought the problem was related to spaces in the directory name, but after doing a test where I include from a directory that does not contain spaces, it's clear that osascript is finding the file and just refusing to open it.

error "Script doesn’t seem to belong to AppleScript." number -1752 from "/path/to/common.applescript"

What does this even mean, and how do I fix it?

Piotr Niewinski
  • 1,298
  • 2
  • 15
  • 27
Ian
  • 11,280
  • 3
  • 36
  • 58
  • Is your AppleScript stored in text format as opposed to compiled script format? – Patrick Wynne Apr 23 '15 at 00:25
  • It's in text format, since it's part of a repository. – Ian Apr 23 '15 at 00:45
  • @Zero that doesn't help me much. Googling that error gives me [information that seems completely unrelated](http://www.macerrorsolution.com/-1752%20errOSABadStorageType.php). – Ian Apr 24 '15 at 19:30

1 Answers1

6

AppleScript's built-in library loader (10.9+) and load script command (all OS versions) require compiled (.scpt/.scptd) AppleScript files [1]. OSA knows nothing about source code file formats (e.g. .applescript) and does not have the ability to read or write them itself; only external tools like Script Editor, osacompile, osadecompile know how to do that.

You can either store the compiled files in your repo [2], or you can write a deployment script that runs the uncompiled (.applescript) files through osacompile when copying them to your Script Libraries folder (or wherever it is you're deploying them).

--

[1] Yes, it's annoying, but OSA predates "modern" SCM systems and its file system interaction was modeled more on Smalltalk machine style persistence, rather than Unix's "let's pretend everything is an ASCII text file" approach.

[2] Though you'll lose the ability to diff them, unless you want to muck about with your SCM's diff hooks so it runs .scpt[d] files through osadecompile to create temporary .applescript files that can then be diffed as normal.

foo
  • 3,171
  • 17
  • 18
  • I have posted a diffscript at [MacScripter / Show differences in two AppleScript files with TextWrangler](http://macscripter.net/viewtopic.php?id=33758) (#post 24) This works with scpt and probably scptd files, as long as it is the main script of a scptd file we are talking about. (Doesn't use scptd that much). – McUsr Apr 23 '15 at 12:06