Tinderbox Forum

How do I make a Tinderbox note with $URL for each open Safari tab?

…asked a user in yesterday’s meet-up. As suspected the answer was AppleScript. I knocked this up after the meet and am happy to say it works (paste code into your Script Editor):

-- ~~~~START CODE~~~~
-- created/tested in script Debugger v8.0.1 on macOS 10.14.6

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Safari"
	
	--Variables
	set windowCount to number of windows
	set docText to ""
	
	--Repeat for Every Window
	repeat with x from 1 to windowCount
		set tabcount to number of tabs in window x
		
		--Repeat for Every Tab in Current Window
		repeat with y from 1 to tabcount
			
			--Get Tab Name & URL
			set tabName to name of tab y of window x
			set tabURL to URL of tab y of window x
			my makeNote(tabName, tabURL)
			
		end repeat
		
	end repeat
end tell

try
	set dialogAnswer to display dialog ¬
		"Data is now copied to the current Tinderbox document." buttons {"OK"} ¬
		default button "OK"
end try


--Write Document Text
on makeNote(tabName, tabURL)
	tell application "Tinderbox 9"
		tell front document
			set myNote to make new note
			set name of myNote to tabName
			set value of (attribute of myNote named "URL") to tabURL
			set value of (attribute of myNote named "DisplayedAttributes") to "URL"
			--set text of myNote to tabURL
		end tell
	end tell
end makeNote
-- ~~~~END CODE~~~~

The user (not IIRC a forum member) has 1,67 Safari tabs open (:dizzy_face: I can’t even… ) but I’m happy to report the above worked and there is now a TBX with 1,061 new notes with each note’s $Name set from the tab title (i.e. the HTML <title> value) and the source URL set in $URL and shown as a Displayed Attribute.

Note: most (all?) Tinderbox-supported macOS version will likely ask permission to access Safari and/or Tinderbox; you will need to allow this for the script to work.

FWIW, why so many tabs open?. Do lots of Zoom meeting where people put useful links in the chat? If you open each as a new browser tab, they can mount up.

Some observations:

  • this is a quick-and-dirty script to get the job done. it makes notes in the current container of the front Tinderbox document. It doesn’t check Tinderbox is open, or if a doc it open etc.
  • if using the same doc to add new such notes, I’d make a prototype for new notes and set that $Prototype value rather than setting $DisplayedAttributes.
  • if using this a lot, consider using Apple’s Automator app to make a service for ‘clipping’ the data to Tinderbox. You could even get Safari to close the tab once done - especially if it is only open to ‘remember’ the title/URL of the recommendation.
  • I’ve only experimented with safari, but I’d suspect similar is possible for Chrome or Firefox.

HTH :slight_smile:

†. Found in Applications ▸ Utilities ▸ Script Editor

3 Likes

Separately, if you find yourself needing to use AppleScript more than occasionally and want a bit more control, do consider LateNight Software’s Script Debugger. Rather like the wonderful BBEdit text/code editor, it has a free version which most (or those on a budget) can use or register for extra whistles and bells (or just because software authors need to eat too!).

No disclaimer needed: I’ve just used both apps since I first switched to using using Macs c.2000 (both apps re-date Tinderbox - '95 and '92 respectively).

Great script, thank you!

Definitely! Although I already modified other people’s scripts and even wrote very simple ones for some years I never really understood what I was doing. Learning about Script Debugger by a recommendation on another forum was a game changer. Now I’m developing quite complex AppleScriptObjC scripts (and recently even started to look into Objective-C as there are some nice-to-have things that aren’t possible in AppleScriptObjC). I have no programming background but with the excellent Script Debugger it’s perfectly doable to learn AppleScript.

1 Like

I forgot to acknowledge that this article gave me a good head start. Essentially I started with that but pointed the output part to Tinderbox as opposed to TextEdit. It does show that even if the exact answer isn’t there already, the pattern for it often does.

I also find https://macscripter.net is a useful place to ask for help on AppleScript related issues.