I think you answered you own question. As you say, ASObjC has “more of it”, “ASObjC dependices are less familiar to newer users” and “ASObjC isn’t documented” - although to be fair, it doesn’t need to be. What you need to do with ASObjC is look at the Cocoa docs. Scripters, insofar as they’ve ever bothered to look at docs, aren’t likely to get much further than the AppleScript Language Guide. Warning them that they need to look further afield, and more often, is pretty much all I was saying. There’s no big headline.
Phil,
Ok, I would have to agree with that. I have taken to reading a lot of Cocoa documents any more and being a scripter I have to admit I really, really hate it. But it’s about being able to do new and better things or just doing the same old limited stuff.
Your remarks are good for me. You are the only one I converse with that talks about the short comings of AppleScript and you have a different perspective then most since you have been a scripter and a developer. Thanks for the thoughts
Bill
On that note, if you haven’t already, do your sanity a favour and buy Dash. Apple’s attempts to provide an interface for their docs - both webwise and within Xcode - are not fit for purpose.
And if you’re not sure, download it and try it – it works free, just with regular pauses.
Just don’t forget to go to Script Debugger’s Preferences -> Editor
and check Option-click opens terms in Dash
.
Phil,
I got Dash while beta testing for SD 6.0 was going on. I updated to version 4.0 when it came out. I really like the the “Inherits From” part at the top of the class documentation. The layout of the side bar is a nice way to got to various sections for the different methods, but I really like that I can see them all laid out in a list instead of going from one to the next use the searches “find next.”
Shane,
I went ahead and paid for dash because I didn’t like the automatic delay.
Bill
Added a new containerOf
function to the library.
Here is an installation script application form MarksLib (and MarkdownLib). This application makes installation simpler and avoids having to copy and paste commands into Terminal.
Install AppleScriptLibraries.zip (71.1 KB)
You can run this application any time to ensure you have the latest version of MarksLib.
UPDATE: Revised the application to include code signing.
Lines 31 and 41 of the README.md show an e.g. between parens but not the surrounding lines. Is that normal?
Little bit of strangenesses. (Not involving the new version of MarksLib, but an older version).
The bug is that when you try to open a library’s dictionary from a script and there is an error, the SD error dialog is whacked the first time it displays.
I wanted to see if the library had a dictionary. It doesn’t, but the way SD reported that is the problem.
I ran a script that opens library dictionaries (below). When a selected script doesn’t have a library SD’s error window should appear. In this case the first time the error dialog appears it’s blank. No text, no buttons, just an empty rectangle. If I hit return the text and buttons appear briefly and then then the error dialog disappears. If I try a second time it works as expected. If I quit and relaunch SD I get the same blank error dialog on first attempt.
I have two versions of Mark’s Lib, and its the older one (.scptd) that appears in the choose from list and doesn’t open a dictionary.
MarksLib.scpt
MarksLib.scptd
(Also, After I download the install app I can’t open it in SD because it’s from an unknown developer. )
–>Script Debugger 6.0.7 (6A213) on Mac OS 10.11.6 (15G17023)
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set scriptLibrariesFolder to path to library folder from user domain as text
set scriptLibrariesFolder to scriptLibrariesFolder & "Script Libraries:"
set myScriptLibraries to my GetFileNames(scriptLibrariesFolder, "scptd")
set listTitle to "Script Libraries"
set listPrompt to "Which script dictionary would you like to try to open?"
set okbuttonName to "This One"
set multipleSelections to true
set emptySelectionAllowed to false
tell application "Script Debugger"
set userChoice to choose from list myScriptLibraries ¬
with title listTitle ¬
with prompt listPrompt ¬
OK button name okbuttonName ¬
multiple selections allowed multipleSelections ¬
empty selection allowed emptySelectionAllowed
end tell
if userChoice is false then return
set scriptList to {}
repeat with thisScript in userChoice
set the end of scriptList to ((scriptLibrariesFolder as text) & thisScript as text) as alias
end repeat
repeat with thisScriptLibrary in scriptList
tell application "Script Debugger"
set myLib to open thisScriptLibrary showing script dictionary
end tell
end repeat
on GetFileNames(folderWithFiles, fileExtension) -- @other stuff
--SecondLine
set folderWithFiles to POSIX path of (folderWithFiles)
set thePaths to current application's NSFileManager's defaultManager()'s contentsOfDirectoryAtPath:folderWithFiles |error|:(missing value)
set fileNames to (thePaths's pathsMatchingExtensions:{fileExtension}) as list
return fileNames
end GetFileNames
MarksLib updates:
- Added
doesFileExist
method to MarksLib - Fixed a bug where
writeToFile
was failing when given an HFS path to a file that does not already exist.
Mark, thanks for sharing.
I ran into one snag that you might want to make note of in your MarksLib.applescript
file.
Since you store it as a text .applescript
file on GitHub, it has to be compiled before using as a script lib. The first compile works fine. But if you compile it again, you get an error because the source code has been changed:
«class from»
is changed to
from
on containerOf(theObject)
# return «class from» of (theObject as record)
return from of (theObject as record)
end containerOf
I remember addressing this issue somewhere, but I cannot seem to find it. Yes, you cannot compile the script twice; you have to restore the «class from»
before compiling each time.
I ran into an issue in Excel where the term “color” was morphing from the needed «property colr» into «class 1097», requiring restoration of the original raw syntax before every compilation.
I got tired of the nuisance and used run script to execute the command as a string. Not sure if this is a good or bad idea, but in the case of MarksLib, it might look like this:
on containerOf(theObject)
run script “return «class from» of (” & theObject & " as record)"
end containerOf
Stan C.
Stan, I like your idea.
FYI, your script block contains fancy quotes and won’t compile. This should do it:
on containerOf(theObject)
run script "return «class from» of (" & theObject & " as record)"
end containerOf
Stan, I like your idea, but I don’t think it will work. Your script forces “theObject” to convert to text value, and will fail on a line like this:
set thePerson to MkLib's containerOf(contents of anItem as record)
Hi Jim,
You’re right of course. As given, my solution does work with variable and handler names, numbers, lists and records that don’t contain strings, raw syntax, and a good bit of AS and application terminology. One could convert strings (or lists and records with strings) to a text format that would work with run script, but that adds complexity and fragility.
References, script objects, and other complex objects. are completely beyond the scope of run script. Use the trick where you can and live with situations where it doesn’t, I guess. And I’m still not sure how wise it is, even when it does work.
Regards,
Stan C.
Since I rarely need to compile MarksLib, I’ll just stick with his original code, which always works.