"Display Random Note" AppleScript not working as intended

Hi there,

I’m using this “Display Random Note” AppleScript available as a downloadable script within DT:

which worked as intended mere days ago. But when I tried to use it today, DT’s log window says

Only groups or local smart groups can be processed by this script.

I tried using the script in four combinations: when a (regular group / local smart group) is (selected / opened in a window). According to the descriptions of the script, all four scenarios are supported, but during my tests all four resulted in the same log message above.

Here are the things I tried:

  1. I re-downloaded the script from the location in the screenshot above. The log message stayed the same for all four combinations.
  2. I duplicated the script file in Finder, and modified the log message in the duplicate so that it’ll output the selectionType after the plain text: log message "Only groups or local smart groups can be processed by this script." & selectionType, but the selectionType in the log message doesn’t make sense to me: «constant ****DTsg» .

I don’t know how to debug the script further, and I’d appreciate it if you could provide some advice or insight! Is this a bug in the script or did I mess up something on my local machine?

P.S. I opened this thread days ago inquiring about using scripts to display a random note, but since my new question is specifically about the built-in “Display Random Note” AppleScript, I decided it’d be better to open another thread. I hope I made the right call there!

A screen cap of what you’re selecting would be good.

Hi Jim, thank you for your help again! :smiley:

Here is a regular group I just tested on:

For the sake of comprehensiveness, here’s the AppleScript I tested on:

-- Display Random Note
-- Originally discussed here: https://discourse.devontechnologies.com/t/random-note-review/25183
-- Written by BLUEFROG / Jim Neumann on Tue Jun 14 2022
-- Copyright 2022 DEVONtechnologies, LLC

(* Opens a random note in a new window from a selected (smart) group or the root of a think window.
- Run, Reminder, and Smart Rule handlers included.
Install in ~/Library/Application Scripts/com.devon-technologies.think3/Menu/Data.
Alias to ~/Library/Application Scripts/com.devon-technologies.think3/Reminders 
Alias to ~/Library/Application Scripts/com.devon-technologies.think3/Smart Rules*)

property docKind : "kind:markdown" -- Set the document kind to open
property validSources : {"group", "smart group"} -- Only process groups and smart groups

-- For manual execution. Process the selection or the current location
on run
	tell application id "DNtp"
		set recCount to (count (selected records))
		if recCount = 1 then
			set theGroup to (selected record 1)
		else if recCount = 0 then -- If there is no selection,  process the root, i.e., the sidebar selection
			set theGroup to root of think window 1
		end if
			my showRandomNote(theGroup)
		on error
			log message "Global smart groups (rules) aren't supported by this script."
		end try
	end tell
end run

-- For use with Reminders set on a (smart) group…
on performReminder(theGroup)
	my showRandomNote(theGroup)
end performReminder

-- For use with smart rules…
on performSmartRule(theGroups)
	my showRandomNote(some item of theGroups)
end performSmartRule

-- Main Handlers ----------------------------

on showRandomNote(theSource)
	tell application id "DNtp"
		-- Check the input type is valid
		set selectionType to (type of theSource) as string
		if (selectionType is not in validSources) then -- If it's not a group, warn and exit.
			log message "Only groups or local smart groups can be processed by this script." & selectionType
			set foundFiles to search docKind in theSource
			if foundFiles ≠ {} then
				set randomRecord to (some item of foundFiles)
				open window for record (some item of foundFiles)
			end if
		end if
	end tell
end showRandomNote

As I mentioned in the main post, the AppleScript above is a modified version of the script downloaded from within DT, and the only modification I made was the added selectionType after the log message “Only groups or local…”.

Does it work after selecting a group in the item list?

Hello Christian, I busted tested it for the first time, using the same regular group and the script that was slightly modified by me. Here is the output in the log window:

Only groups or local smart groups can be processed by this script.«constant ********»	

What did you actually modify and which version of macOS do you use? And did you select a group in the item list (not just in the sidebar) as suggested?

I just remembered something that I believe is unrelated to the unexpected behavior of the script in question, but I’ll post it here just in case: I’m running macOS Sonoma version 14.0(23A339).

The reason that I believe it’s unrelated is that when the script was working as intended a few days ago, I was already running the same version of macOS Sonoma. Though I guess you can never be sure when it comes to betas.

Here’s a timeline to make things clearer:

  • Sept 18th: I installed the public beta of Sonoma for the first time
  • Sept 20th: I posted this forum thread, where @BLUEFROG informed me of the existence of the “Display Random Note” script, and I tested that it worked perfectly both for regular groups and local smart groups
  • Sept 22th, today: I found out the “Display Random Note” script was not working as intended for me

Hi Christian,

Also, I made this modification in an attempt to troubleshoot the issue and solve it myself; the original, unmodified script was already not working as intended for me.

Yes, I tried four scenarios, including the one you mentioned:

Open a support ticket. I’ll look at it after i wake up :sleeping:

Will do. Thank you for your patient help as always and rest well! :slight_smile:

JFTR: I run your version of the script here on selected groups and on a group of files in the view window – worked fine without a glitch. But I’m still on Ventura.

1 Like

Thank you for the confirmation on your side, chrillek! That makes it all the more possible that the issue is specific to Sonoma.

P.S. The script worked perfected for me on this same build of Sonoma, so I totally forgot to mention that I am on a beta version of the OS. Now I’m feeling bad that I’m likely reporting a beta-only bug.

You’re welcome. I have the ticket and just responded.

1 Like