Late Night Software Ltd. - Latest topicshttps://forum.latenightsw.com/latest
Latest topicsWed, 03 Jun 2020 02:17:02 +0000Disable "persistent variables" by default?Script DebuggerIs it possible to add a preference option that would disable “Persistent Variables” by default? I’m constantly tripping over situations where a variable gets set in one run of a script and triggers an unwanted action later. I know I can turn it off, and I know I can create run-only scripts, but I want users to be able to edit my scripts, and it would make life easier if I could assume that Persistent Variables were switched off unless I explicitly turned them on.

Of course I can imagine that there are many reasons NOT to do this, but I hope it might be worth considering.

]]>https://forum.latenightsw.com/t/disable-persistent-variables-by-default/2510
Wed, 03 Jun 2020 02:17:02 +0000NoNoNoforum.latenightsw.com-topic-2510Disable "persistent variables" by default?Improved UI for Enhanced AppletsFeature RequestsIt would be nice to add some features to Enhanced Applets to allow the customization of their appearance. It would be helpful to set their window length and width as well as on screen position. It would also be nice if either a background image or an icon could be added to the progress bar window to allow for some branding, if possible.

I appreciate the options available for branding the droplet window, however I am not using the UI to drop items, and would love those options available without the need to drop items on it.

]]>https://forum.latenightsw.com/t/improved-ui-for-enhanced-applets/2508
Tue, 02 Jun 2020 18:44:03 +0000NoNoNoforum.latenightsw.com-topic-2508Improved UI for Enhanced AppletsUI for Enhanced AppletsScript DebuggerIs there a way to set a background image or change the overall dimensions of the Progress Window of an Enhanced Applet? I am trying to use is just as an interface and not a drop window, but I would love to set the bounds of the window and perhaps add an image or icon. Thanks

]]>https://forum.latenightsw.com/t/ui-for-enhanced-applets/2506
Mon, 01 Jun 2020 19:10:38 +0000NoNoNoforum.latenightsw.com-topic-2506UI for Enhanced AppletsNew Forum Bookmark FeatureSite FeedbackMark @alldritt, I really like the new Discourse Bookmarks Feature. Is that now a native feature, or did you need a plug in to get it?

]]>https://forum.latenightsw.com/t/documentation-as-epub/2502
Mon, 01 Jun 2020 07:59:07 +0000NoNoNoforum.latenightsw.com-topic-2502Documentation as ePUBWarning about new Dropbox Mac backup featureUncategorizedAfter transferring my Catalina system to a replacement SSD, Dropbox offered to setup a new system that backs up my Desktop, Documents, and Downloads folder. Apparently this system is in beta, and is offered only some setups, and my new disk triggered the offer when Dropbox recognized that I was using a new disk and required me to log in and set up Dropbox on the disk.

Thinking this backup might be a good idea, and not reading the fine print, I clicked Yes, and then a lot of my scripts stopped working. If I ran a script from the desktop, the problem occurred with the first line that ran a shell script that (for example) copied a file stored inside the applet; that line produced an “Unexpected token near position 0” error (or something similar; I’m writing from memory).

It turned out that Dropbox had moved all my Desktop files into the Dropbox folder, leaving symlinks behind, and that any script that I ran that referred to the POSIX path of the applet itself now used a path that had parentheses in it - and the first parenthesis was the “unexpected token.”

After I got rid of the Dropbox backup system and moved the backed-up files back to my desktop, most of them worked, but one kept giving a “not authorized to send Apple events to the Finder” error, no matter how many permissions I gave it. Possibly I could have tracked down every hidden cached reference to that script, but it wasn’t worth the effort, so I fixed the problem by drastic means: I removed the whole Catalina system from my new disk, and restored it again from a Carbon Copy Cloner backup of the old disk. I had to reinstall Catalina to make it work, but everything in my user folders was intact and functional.

Needless to say, if Dropbox offers to back up your Mac desktop, documents, and downloads folder, don’t do it. But the more troubling question is this. Because other people will turn this feature on, and break some scripts that are run from the backed-up folder and use Unix paths to themselves, how can a script test for this and either work around the issue or warn the user to move the script to some other location?

Also, though I don’t want to experiment with this again, if the persistent problem I had with “Not authorized to send Apple events to the Finder” is something that can’t be fixed in any user-friendly way (and possibly only by restoring a whole system from a backup), would a test like this be enough to prevent it from happening? (I know I’m asking only for speculation here.)

Again, this won’t affect scripts that don’t use POSIX paths to themselves, and won’t affect all such scripts, but it seems like a very serious potential problem.

]]>https://forum.latenightsw.com/t/notarize-app-steps/2495
Fri, 29 May 2020 13:40:04 +0000NoNoNoforum.latenightsw.com-topic-2495Notarize app steps?Myriad Tables "self-feeling" of checkbox and pop-up menuAppleScriptDear all,
I looked into the examples provided with Myriad Tables and in the forum(s), but I could find a way to have several checkboxes linked together.

What I mean is that if I select one, on other one is “automatically” de-selected. Like in the example below only rows 1, 2 , and 3 are correct.
I would like that the user never can set the options as in row 4.

The only way I solved this (so far) is to analysed the results after the user click “OK” and if are inconsistent, then make the table appear again (with a forever-loop).

]]>https://forum.latenightsw.com/t/myriad-tables-self-feeling-of-checkbox-and-pop-up-menu/2494
Fri, 29 May 2020 07:14:18 +0000NoNoNoforum.latenightsw.com-topic-2494Myriad Tables "self-feeling" of checkbox and pop-up menuNeed help with script libraryScript DebuggerHi all,
I’m very very new to Applescript as well as script debugger. I hope to get your kind help about a small issue. I’m learning the script debugger with the video tutorial and want to try using the script library. I followed the steps in the video.
I save a script containing a FirstN handler in the script library.
And then I try to use this handler in a new script. But when I tried to connect the two script in the resource window. I can’t find anything to add the library script.

]]>https://forum.latenightsw.com/t/need-help-with-script-library/2492
Thu, 28 May 2020 20:45:54 +0000NoNoNoforum.latenightsw.com-topic-2492Need help with script libraryHow to do a variable rename?Script DebuggerI’m just trying out Script Debugger and it is certainly a step up from Script Editor!

One feature I’m used to from other IDEs is simple refactoring, i.e. symbol renaming. For example is it possible to rename a variable in its definition and all its uses?

]]>https://forum.latenightsw.com/t/how-to-do-a-variable-rename/2487
Wed, 27 May 2020 02:10:45 +0000NoNoNoforum.latenightsw.com-topic-2487How to do a variable rename?How an AppleScript applet can get the frontmost application other than itselfAppleScriptI hope I am asking the question in the right way:
I am writing a script that will be saved as a script application so that I can attach a shortcut keys to it either by BTT or through Automator services. One handler within the script is to extract the URL address of the frontmost browser if I am calling the script while I am using the browser.

The problem: since the script itself is already an app, so the frontmost application will always be the script instead of the browser while I am using the browser. BTT offers an option to run the script application in background (so the handler will work) but it seems that automator>quick action doesn’t have such option?
I hope someone can suggest a solution for this?

Thank you very much!

on getWebLink()
-- this line will always return the name of the script application
tell application "System Events" to set theApp to name of first application process whose frontmost is true
if "Safari" is in theApp then
tell application "Safari"
set theWebURL to URL of front document
set theWebName to name of front document
return "[Source: " & theWebName & "](" & theWebURL & ")"
end tell
else if "Chrome" is in theApp then
tell application "Google Chrome"
set theWebURL to URL of active tab of front window
set theWebName to title of active tab of front window
return "[Source: " & theWebName & "](" & theWebURL & ")" & return & return
end tell
else
return ""
end if
end getWebLink

]]>https://forum.latenightsw.com/t/how-an-applescript-applet-can-get-the-frontmost-application-other-than-itself/2482
Tue, 26 May 2020 13:32:27 +0000NoNoNoforum.latenightsw.com-topic-2482How an AppleScript applet can get the frontmost application other than itselfRemembering FaceSpanAppleScriptI was going through some archives and ran across items relating to my FaceSpan project. I’m still very sad that I was not able to make that project a success.

For those that don’t know, FaceSpan was a Rapid Application Builder based on AppleScript. You dragged UI components into a canvas and attached bits of AppleScript code to respond to events (button presses, etc.). The original FaceSpan (then called Frontmost) shipped with AppleScript 1.0. I acquired FaceSpan 4 and attempted to remove its dependance on AppleScript Studio. Sadly, it didn’t work out.

I have a script that I’ve been working on for weeks that has been running flawlessly. I used yesterday. I tried to open it this morning and got that message. In SD I tried to see previous version via the revert menu but all of them had that same message.

]]>https://forum.latenightsw.com/t/applescript-failed-to-retrieve-the-scripts-source-code/2474
Sat, 23 May 2020 16:48:16 +0000NoNoNoforum.latenightsw.com-topic-2474AppleScript failed to retrieve the script's source codeNeed help with some weird problem involving properties and signingAppleScriptI’m experiencing some weird problem. It looks like some property value is persisted. Also, it seems that the property is set only on the first assignment, and after that it can’t be changed. But that would be really weird. I can’t reproduce the behaviour though. The situation is something like this script:

In my real situation (above is my trial to isolate) the value in the alert doesn’t change after the first run. In the script above, it does.

However, one thing I noticed: when I check the signature with WhatsYourSign right after it is compiled, the signature is valid. After it has ran, the app has signing issues… (sign auth: unknown (status/error: -67054)_

So could one advise on why the signature is not valid anymore? And does anyone recognize this weird property behaviour? Any pointers?

]]>https://forum.latenightsw.com/t/need-help-with-some-weird-problem-involving-properties-and-signing/2470
Wed, 20 May 2020 10:32:42 +0000NoNoNoforum.latenightsw.com-topic-2470Need help with some weird problem involving properties and signingAppleEventsUsageIn XcodeI’ve an app using tell blocks for other apps i.e.
tell application “Finder”
…
end

We are pleased to announce the release of SD Notary 1.4.2. SD Notary is a tool for notarizing AppleScript and Automator apps. Please see this blog post for more information. This update can be applied using SD Notary’s Check For Updates command (in the SD Notary menu). Alternatively, you can download the latest version from…

]]>https://forum.latenightsw.com/t/can-the-mac-notifications-center-be-scripted/2461
Sun, 17 May 2020 20:53:31 +0000NoNoNoforum.latenightsw.com-topic-2461Can the Mac Notifications Center be Scripted?NSTextField undo last entryIn XcodeIs there a method to undo the last character entered by the user in a NSTextField?
TIA!

]]>https://forum.latenightsw.com/t/nstextfield-undo-last-entry/2458
Sun, 17 May 2020 12:41:19 +0000NoNoNoforum.latenightsw.com-topic-2458NSTextField undo last entryNeed Help Sorting a List of Strings Based on Its SubstringAppleScriptHey guys, I need a bit of help sorting a list. It’s a bit complicated because I need to sort based on a substring of each item in the list.

]]>https://forum.latenightsw.com/t/need-help-sorting-a-list-of-strings-based-on-its-substring/2456
Fri, 15 May 2020 21:27:07 +0000NoNoNoforum.latenightsw.com-topic-2456Need Help Sorting a List of Strings Based on Its SubstringTrouble loading code from my personal applescript fileScript DebuggerI’m not sure if this is a debugger question or just a newbie not knowing his way around, but I thought I’d put this here and see what happens.
I have two scripts, one called “RC_applescript.scpt” which contains this code:

property rclibx : 5

The second script is called “evernote.scpt” and contains this code:

set rclib to load script file ((path to home folder as string) & "RC_applescript:RC_applescript.scpt")
tell rclib
set its rclibx to (its rclibx) + 7
end tell

When I run evernote.scpt, it gives this error in the debugger:Can’t get rclibx of «data scpt4D617259332E3030000blah blahEDEAD».

what is going on? The library loads but I can’t access anything in it…

]]>https://forum.latenightsw.com/t/sqlite-lib2-released/2450
Thu, 14 May 2020 12:15:11 +0000NoNoNoforum.latenightsw.com-topic-2450SQLite Lib2 releasedApplescripting Links in KeynoteAppleScriptI have been looking without success into scripting links between slides in Keynote. It does not appear to be in the dictionary - nor in that for Pages as well - and I am uncomfortable with UI scripting. If it isn’t in there, does anyone know if Apple Events might be a possibility or am I just out of luck on this one? Thanks in advance for your assistance.

]]>https://forum.latenightsw.com/t/applescripting-links-in-keynote/2449
Wed, 13 May 2020 21:20:48 +0000NoNoNoforum.latenightsw.com-topic-2449Applescripting Links in KeynoteEscape String Literals in a scriptScript DebuggerIn scripting ScriptDebugger, is there an equivalent to the “Paste as String Literal” menu option.

Ideally I’d like to take a chunk of text with quotes and slashes and convert them to text with the quotes and slashes escaped.

If there’s not a scripting command that will do that, then I request it!

]]>https://forum.latenightsw.com/t/database-events-and-myriad-tables/2443
Thu, 07 May 2020 15:23:25 +0000NoNoNoforum.latenightsw.com-topic-2443Database Events and Myriad TablesEpically slow script - any thoughts on how to improve?AppleScriptThe script below is exceptionally slow. It ingests a JSON file and then does various DevonThink things to it.

If I feed it a small JSON file, each iteration of the main repeat loop is fairly quick (a second or so). If I feed it a larger file, the time for each iteration of the repeat loop increases, to as much as 30 seconds per iteration.

I assume this has to do with the data structures involved. I know very little about Applescript - any thoughts about how to optimise this?

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
-- all the settings should be here
set bibJSONFile to "/Users/lyndon/repo/workflow/zot-export-bbt.json"
--set thePListFile to "/Users/lyndon/repo/workflow/zotero-to-devonthink.plist"
set theTemplateFile to "/Users/lyndon/Library/Application Support/DEVONthink 3/Templates.noindex/Education/Reference LD.md"
set theDTDBFile to "/Users/lyndon/DevonThink/Research.dtBase2"
set theDTLocation to "/Library"
set theModName to "_mod_datetime_zotero.txt"
set theDictionaryName to "_dictionary_zoteroid_uuid.txt"
--
set ca to current application
property NSJSONSerialization : a reference to current application's NSJSONSerialization
property NSJSONWritingPrettyPrinted : a reference to 1
property NSData : a reference to current application's NSData
property NSString : a reference to current application's NSString
-- a helper method to replace any substring with a space
on remove:remove_string fromString:source_string
set s_String to NSString's stringWithString:source_string
set r_String to NSString's stringWithString:remove_string
return s_String's stringByReplacingOccurrencesOfString:r_String withString:" "
end remove:fromString:
set theJSONData to NSData's dataWithContentsOfFile:(bibJSONFile)
set theJSON to NSJSONSerialization's JSONObjectWithData:theJSONData options:0 |error|:(missing value)
set theCurrentTime to current date
set bibjson to theJSON as record
set therefs to |items| of bibjson
set mainDict to missing value
set theDictRecord to missing value
-- load up the previous data
tell application id "DNtp"
set theDatabase to open database theDTDBFile
set theLocation to create location theDTLocation in theDatabase
-- set mainDict to current application's NSMutableDictionary's dictionaryWithContentsOfFile:thePListFile
if mainDict is missing value then
set mainDict to current application's NSMutableDictionary's new()
end if
tell theLocation
set theDictPath to theDTLocation & "/" & theDictionaryName
set theDictRecord to get record at theDictPath
if theDictRecord is missing value then
set theDictRecord to create record with {name:theDictionaryName, type:"txt"} in theLocation
end if
if theDictRecord is not missing value then
set mainDictContents to plain text of theDictRecord
set mdStr to (ca's NSString's stringWithString:mainDictContents)
set mdDataDict to item 1 of (ca's NSJSONSerialization's JSONObjectWithData:(mdStr's dataUsingEncoding:(ca's NSUTF8StringEncoding)) options:0 |error|:(reference))
mainDict's setDictionary:mdDataDict
end if
end tell
-- set theChildGroups to {}
-- try
-- set theChildGroups to children of theLocation
-- end try
-- repeat with theChild in theChildGroups
-- if type of theChild is group then
-- set theZoteroIDString to get custom meta data for "zoteroid" from theChild
-- set theUUID to uuid of theChild
-- (mainDict's setObject:theUUID forKey:theZoteroIDString)
-- end if
-- end repeat
end tell
set limitCounter to 0
repeat with theRef in therefs
set limitCounter to limitCounter + 1
-- if (limitCounter > 20) then exit repeat
set {theKey, theTitle, theURI, theZoteroID, theDateModified} to {citationKey, title, uri, itemID, dateModified} of theRef
set theSelectURI to ""
try
set theSelectURI to |select| of theRef
end try
try
set theTitle to |shortTitle| of theRef
end try
set theZoteroIDString to theZoteroID as string
set theDOI to ""
try
set theDOI to DOI of theRef
end try
set theAbstract to ""
try
set theAbstract to abstractNote of theRef
end try
set theDate to ""
try
set theDate to |date| of theRef
set theReferenceYear to theDate
end try
set theURL to ""
try
set theURL to |url| of theRef
end try
set theCreators to ""
set multipleCreators to ""
try
repeat with theCreator in creators of theRef
try
set theCreators to theCreators & multipleCreators & |firstName| of theCreator & " " & |lastName| of theCreator & " (" & |creatorType| of theCreator & ")"
set multipleCreators to " and "
end try
end repeat
end try
set theTags to {}
try
repeat with theTagItem in tags of theRef
set theTags to theTags & tag of theTagItem
end repeat
end try
-- construct group name and look for a previous group in the dictionary
set theGroupFile to theKey & " " & theTitle
set theGroupFile to (my remove:"/" fromString:theGroupFile)
set theUUID to missing value
set theUUID to (mainDict's objectForKey:theZoteroIDString)
-- create or update the group
if theUUID is missing value then
tell application id "DNtp"
set theGroup to create location theDTLocation & "/" & theGroupFile
set theUUID to uuid of theGroup
end tell
else
set theUUID to theUUID as string
tell application id "DNtp"
set theGroup to get record with uuid theUUID
if theGroup is missing value then set theGroup to create location theDTLocation & "/" & theGroupFile
set the name of theGroup to ("" & theGroupFile)
set theUUID to uuid of theGroup
end tell
end if
-- create or update a summary file
set theSummaryName to ("___" & theGroupFile & ".md") as text
set theSummaryDate to theDate
set theSummaryPlaceholders to {|%reference%|:theTitle, |%authors%|:theCreators, |%date%|:theSummaryDate, |%citation%|:theKey, |%doi%|:theDOI, |%abstract%|:theAbstract, |%zoteroselect%|:theSelectURI}
tell application id "DNtp"
set theTempRecord to import theTemplateFile placeholders theSummaryPlaceholders to theGroup
set thePrevSummaryName to get custom meta data for "referencesummaryfile" from theGroup
if thePrevSummaryName is missing value or thePrevSummaryName = "" then
set theSummaryRecord to get record at (the location of theTempRecord) & theSummaryName
else
set theSummaryRecord to get record at (the location of theTempRecord) & thePrevSummaryName
end if
if theSummaryRecord is missing value then
set the name of theTempRecord to theSummaryName
set theSummaryRecord to theTempRecord
else
set theTempContent to the plain text of theTempRecord
set the plain text of theSummaryRecord to theTempContent
delete record theTempRecord
set the name of theSummaryRecord to theSummaryName
end if
end tell
(mainDict's setObject:theUUID forKey:theZoteroIDString)
tell application id "DNtp"
tell theGroup
set aliases to theKey
set tags to theTags
set URL to theSelectURI
set custom meta data to {referencesummaryfile:theSummaryName, DOI:theDOI, abstract:theAbstract, citekey:theKey, zoteroid:theZoteroID}
end tell
end tell
-- add attachments and bookmarks to the group
if theURL ≠ "" then
tell application id "DNtp"
set theBookmarkRecord to lookup records with URL theURL
if theBookmarkRecord is missing value or (count of theBookmarkRecord) is less than 1 then
create record with {name:theURL, type:bookmark, URL:theURL} in theGroup
end if
end tell
end if
set theAttachmentPath to ""
set attachmentList to {}
try
set attachmentList to attachments of theRef
end try
repeat with theAttachment in attachmentList
set theAttachmentPath to ""
set theAttachmentURI to ""
set theAttachmentURL to ""
set theAttachmentLinkMode to ""
try
set theAttachmentPath to |path| of theAttachment
end try
try
set theAttachmentURI to uri of theAttachment
end try
try
set theAttachmentURL to |url| of theAttachment
end try
try
set theAttachmentLinkMode to linkMode of theAttachment
end try
if theAttachmentPath ≠ "" then
tell application id "DNtp"
tell theGroup
set theAttachmentRecord to lookup records with path theAttachmentPath
if theAttachmentRecord is missing value or (count of theAttachmentRecord) is less than 1 then
set theAttachmentRecord to indicate theAttachmentPath to theGroup
else
set theAttachmentRecord to item 1 of theAttachmentRecord
end if
if theAttachmentRecord is not missing value then
set custom meta data of theAttachmentRecord to {DOI:theDOI, abstract:theAbstract, citekey:theKey, zoteroid:theZoteroID}
end if
end tell
end tell
else if theAttachmentLinkMode = "linked_url" then
tell application id "DNtp"
set theBookmarkRecord to lookup records with URL theAttachmentURL
if theBookmarkRecord is missing value or (count of theBookmarkRecord) is less than 1 then
create record with {name:theAttachmentURL, type:bookmark, URL:theAttachmentURL} in theGroup
end if
end tell
end if
end repeat
end repeat
set theMainDictJSONData to (NSJSONSerialization's dataWithJSONObject:mainDict options:NSJSONWritingPrettyPrinted |error|:(missing value))
set theMainDictJSONString to (ca's NSString's alloc()'s initWithData:theMainDictJSONData encoding:(ca's NSUTF8StringEncoding))
set theMainDictJSONStringAS to (theMainDictJSONString as text)
tell application id "DNtp"
tell theGroup
set plain text of theDictRecord to theMainDictJSONStringAS
-- (mainDict's writeToFile:thePListFile atomically:true)
end tell
end tell

]]>https://forum.latenightsw.com/t/dt-coding-series-part-3-getting-started-with-applescript-for-capture-one/2436
Sun, 03 May 2020 20:51:22 +0000NoNoNoforum.latenightsw.com-topic-2436DT Coding Series, Part 3: Getting Started with AppleScript for Capture OneKind of RTF questionAppleScriptI use ‘Outline’ as an attribute (or as one of the attributes).
Everything is okay up to a certain outline width. Depending on font I’ll get the joint-spikes like with a W and Arial.

]]>https://forum.latenightsw.com/t/kind-of-rtf-question/2434
Sat, 02 May 2020 13:37:36 +0000NoNoNoforum.latenightsw.com-topic-2434Kind of RTF questionHow to use shell script to format a date string variable within AppleScript?AppleScriptI am a beginner in AppleScript who trys to use shell script in AppleScript for formatting a data string variable. For example, a variable theDate that is defined as: set theDate to "Sunday, 3 May 2020 at 14:15"

From the internet, I learn how to format the current date into various formats (see the code block). But I have no idea how to pass the variable theDate to the shell script?

Thank you very much in advance!

set theYear to do shell script "date +%Y "
set theMonthNum to do shell script "date +%m "
set theMonthLongName to do shell script "date +%B "
set theMonthShortName to do shell script "date +%b "
set theWeekNum to do shell script "date +%V "
set theDayNum to do shell script "date +%d "
set theWeekDayShort to do shell script "date +%a "
set theWeekDayLong to do shell script "date +%A "
set theCurrentTime to do shell script "date +%H:%M "
set theCurrentTimeAMPM to do shell script "date +'%I:%M %p' "

]]>https://forum.latenightsw.com/t/how-to-use-shell-script-to-format-a-date-string-variable-within-applescript/2433
Fri, 01 May 2020 13:21:05 +0000NoNoNoforum.latenightsw.com-topic-2433How to use shell script to format a date string variable within AppleScript?Need Help Scripting Google DriveAppleScriptHey guys, anyone have any experience with scripting Google Drive on the Mac?

I need to do the following:
Given the path to a file in a Google Drive folder on the Mac, get the:

Shared Link URL

HTML Embed Code

Any help or suggestions will be greatly appreciated.

The Google Drive app, “Backup and Sync from Google.app” has no scripting support.
But once installed, it does provide a context menu:

I just learned about SD Notary and it looks great! Are there any special instructions or requirements for the Developer ID signing identity to show up in the dropdown? I’ve been compiling and submitting apps (through XCode) on this machine forever, redownloaded all the developer and distribution certificates from Apple’s developer page, but the dropdown keeps saying ‘No Developer ID identities found’.