Strange ASObjC Error When Running RegexAndStuff Lib from FastScripts

Continuing the discussion from RegexAndStuffLib Script Library:

@ShaneStanley, I love your Regex Lib and it always works great from SD7.
But I’m getting this error running my complex scripts and your simple example script from FastScripts:

image

Error Number: -1708

NSRegularExpression doesn’t understand the “regularExpressionWithPattern_options_error_” message.

I get the same error running from Keyboard Maestro.

Running Fastscripts 2.7.8 (817) on macOS 10.14.5 (Mojave).

The first few times I ran the script worked fine. Then, for no apparent reason, it starting throwing this error. Same with my complex script.

Any ideas?

Here’s the script:

use AppleScript version "2.5"
use framework "Foundation"
use framework "AppKit" -- this may not be required
use scripting additions

use script "RegexAndStuffLib" version "1.0.3"

set newStr to regex change "one two three" search pattern "t(.?)" replace template "t**$1**"

set currentApp to path to frontmost application as text

tell application currentApp
  set msgStr to newStr
  set msgTitleStr to "Test RegexAndStuff Lib"
  display dialog msgStr with title msgTitleStr
end tell

--> "one t**w**o t**h**ree"
return newStr

I can’t reproduce that here with FastScripts (I don’t have Keyboard Maestro). Anyone else?

That error is what you would see if you modified the library to remove/comment out its use framework "Foundation" statement. Have you edited it at all?

(You don’t need the use framework statements in your sample calling script, although it shouldn’t make any difference.)

I presume you’ve quit and relaunched both apps.

Same here.


MacOS 10.12.6 (16G2016)
Script Debugger 7.0.8 (7A80)
FastScript 2.7.8

I should add that apps like FastScripts and Keyboard Maestro use a single instance of AppleScript, so once one script loads a library, it is cached and that version is used from then on, and in any scripts that use it. So if you edit or update a script library used in these apps, you should relaunch them.

1 Like

Thanks, Shane, I was not aware of this. I will definitely do so.

In the meantime, I have avoided the issue by using my RegEx handler, and including it internally in the main script file. No errors or problems with this method.

Shane, sometimes the error does not occur until I run the script 3-4 times, maybe more.
Have you tried that?

I have not. And the error has occurred in not only your Script Lib, but my own Script Lib.

A thought just occurred: I’m using a SymLink for “Script Libraries” in my ~/Library folder to point to another folder I have in my Dropbox folders. Could this be a factor?

Numerous times, and it even occurs after a Mac restart.

Any ideas?

Yes — quite a lot of times.

For any libs that are packages (.scptd files), almost definitely. For .scpt files, possibly. You say it happens with your own lib — is that saved as a .scptd file?

Perhaps you could try removing the symlink for a day or so, and see how it goes.

Great idea, Shane! :+1:

So far, with only a moderate testing of one script, that seems to have fixed the issue.
Script is working fine from both FastScripts and Keyboard Maestro.

Here’s the script I used:

use AppleScript version "2.5" -- El Capitan (10.11) or later
use framework "Foundation" -- this may not be required
use framework "AppKit" -- this may not be required
use scripting additions

use script "RegexAndStuffLib" version "1.0.4"

set someText to "This is an IP address: 192.168.5.128"
set reFind to "(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)"

--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--»   Using Shane's new RegexAndStuffLib Library
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

try
  set reMatchList to regex search someText search pattern reFind capture groups {}
  set AppleScript's text item delimiters to linefeed
  set matchListStr to reMatchList as text
  set scriptResults to "Match List Found by Regex Script Lib:" & linefeed & matchListStr
  
on error errMsg number errNum
  set scriptResults to "[ERROR] #" & errNum & linefeed & errMsg
  set the clipboard to "Script: " & (name of me) & linefeed & scriptResults
end try

set currentApp to path to frontmost application as text

tell application currentApp
  set msgStr to "Match List Found by Regex Script Lib:" & linefeed & matchListStr
  set msgTitleStr to (name of me)
  display dialog scriptResults with title msgTitleStr ¬
    with icon stop
  --etc
end tell

return scriptResults

Great. Let us know if there’s any change.

Hey Shane,

This is true of FastScripts but NOT true of Keyboard Maestro.

Keyboard Maestro uses osascript to run AppleScripts, and changes to a library will show up immediately on the next run of a script using it.

We’ve been trying for years to get Peter to change the AppleScript-runner mechanism in KM, but he maintains other methods are buggy and crash the Keyboard Maestro Engine.

I don’t have the expertise to test this and therefore cannot refute what he says, but I run many scripts many times a day with FastScripts – and it almost never crashes.

The only crash I see regularly with FS has to do with its UI and type-selecting within the open menu – and this only happens once in a blue moon.

-Chris

Thanks — I should have remembered that. That’s all the more reason why having the Script Libraries folder under Dropbox’s spell is likely to end in grief.

Hey Shane,

Do tell. What are the obvious (and not so obvious) pitfalls?

The only thing I’m currently aware of is that some apps will properly chase symlinks, and some apps like FastScripts will only chase aliases.

Personally I’d like to move my ~/Library/Scripts folder into my ~/Documents/Application Support Files/ folder, so Spotlight can search them properly – but it’s been too much of a hassle to bother with so far.

-Chris

Dropbox has problems with packages. It sees them as directories (which they are), but the items in them can be modified at different times and get out of sync. That’s problematic with .scptd files. A search on Google should dig up the gory details.

And if my memory serves me, this isn’t the first time Jim’s been hit with this sort of thing. I think it was with Myriad Tables last time.

1 Like

Shane, I don’t recall any issues with Myriad Tables. I did discover an issue with SD6 Beta support of symlinks and alias files, but you guys fixed that before release.

Sorry, Jim — it was with one of my other libs:

Shane, I just reread that thread, and I don’t think the issue I reported here in my OP is related to the SQLite Lib issues:

IAC, accessing script libs seem to be working fine now that I have removed the symlink in the ~/Library folder and reverted to using the actual Script Libraries folder. Of course, this changes two things:

  1. Removes use of SymLink
  2. Removes use of DropBox