What Do You Use for Code Management or Snippet Management?

Continuing the discussion from How Do I Create Zip File in AppleScript and Retain Finder Tags?:

Thanks for the suggestion.

I haven’t tried this app, but I did find one incorrect statement on their web page:

Spotlight doesn’t even allow us to search our Applescript code files and Spotlight doesn’t index all of the folders that hold our other types of source code

Spotlight does search inside of .scpt files, as least for macOS 10.12.6. I just tested it. The Finder will also provide a preview by just pressing the SpaceBar.

I have arrived at using the macOS file system, plus a text expander like Typinator, after a long and tortuous path. I have tried extensively many code snippet managers (but not Scriptlight) and have found them all lacking in some respect. Maybe ScriptLight is better, I don’t know. If any of you think so, please share its advantages over what I have shared here using the macOS+.

Although I initially discounted using the macOS files with Finder, Path Finder, Spotlight (general and in Finder), I have now come to the conclusion that it is the best “snippet” manager, where “snippet” means all my scripts, whether 10 lines or 3,000 lines.

The final feature that pushed me over the hump was using Finder Tags. I’ve been using them now for about a year, so most of my useful scripts have tags. I find it very easy to assign tags in the Save As dialog, to add/change tags in the Finder, and to search for files using Finder Spotlight. In all cases the system provides me with a great auto-completion when selecting a tag. One key factor is that I make good use of prefixes for most of my tags.

Some examples of my Tag Prefixes

Lang.AS
Lang.ASObjC
Lang.Bash
Lang.JS
Lang.JXA
. . .

SW.AMail
SW.BBEdit
SW.Chrome
SW.Contacts
. . .

CAT.Files
CAT.Find
CAT.Handler
CAT.HTML
CAT.Lists
CAT.Strings
. . .

These prefixes make selecting a tag very easy, acting like a drop-down list:

Demo Tag Selection

Tag-Selection-Save-As-AN

The tag I use the most, Lang.AS, is the easiest to select. All I have to do is type l, it is auto-selected, then I press RETURN to assign. Next if I press l again, it auto-selects Lang.ASObjC because it knows I have already selected Lang.AS.

This same auto-complete drop-down list works in Save As dialog, Finder Search, Finder Assign Tags, PF Assign Tags, etc.

Thanks to @ShaneStanley, I have 5 great Finder Tag scripts:

  1. Get List of All Tags
  2. Get Tags assigned to a File
  3. Replace All Tags assigned to a File
  4. Add Tags to File
  5. Compress Files with Tags and retain the Tags

One other great benefit of using Spotlight is that I can search on a specific subject and it will find all related files/documents, including:

  • Scripts
  • EMail
  • Evernote Notes
  • Local HTML docs
  • PDFs
  • Keyboard Maestro Macros
  • etc.

With Spotlight I can:

  • Use on-the-fly search criteria
  • Modifiable Saved Searches
  • Just enter text, and it find that text in file name and file contents and tags
  • In general Spotlight, I can select text (e.g. code snippets) in the auto-preview

I can also select text in the Path Finder Preview Panel.

With Typinator, I can search for and enter script handler calls from my Script Libs into SD.

So, lots of independent features of the macOS and key apps come together synergistically to make a great code/snippet manager.

2 Likes

But only if you have installed Script Debugger. Those things rely on Script Debugger’s Spotlight importer and QuickLook filter.

I never thought of using prefixes. Thank you for the tip. For tag management I use a System Preference set shortcut for Finder > Tags…
I mostly use tags for my jobs, to indicate their status (quote/current/to invoice/invoiced/paid, etc.) and plenty of other tags for stuff I want to read. I guess I don’t have as much code as you do so I never needed to tag my code files.

I’m using Shane’s tags handling script too.

I can’t/don’t manage anything (it’s a bug, not a feature), but that’s why I find SD’s ‘open quickly’ such a boon.

Aside from that, BBEdit’s Multi file search is pretty good.

Also, every script I write is first saved in a /bin/applescripts folder now, then either I alias it to where needed or make a duplicate.

Snippets – i have so many apps that have a snippet manager I’ve lost count; don’t get along with any of them. I do make some limited use of the one in Xcode, but not much. Mostly, I rely on the fact that I have a number of major projects that, combined, have pretty much everything I’ve ever written in them.

I’ve never gotten along with tags. Tried a few times and just, nah.

Phil, could be a mindset.

TL;DR: Using Tags could be worthwhile, but you will need to make the investment and disciple to make them work. OR, the logic of tags just may not work for you. :smile:

I’m a long-time Evernote user (10+ years) and the “best” way to organize your Notes is debated endlessly. Having watched, and participated in, this for years, I’ve come to the conclusion that what is logical to one man (woman) is noise to another. (you know the ole trash/treasure saying) LOL

There are clearly two major camps: Those that tag, and those that do not.

However, since the Evernote Notebooks (like folders) are very limited (max of 250, no hierarchy), but tags are virtually unlimited, Evernote has in essence pushed tags onto us. I have to say that I am a strong advocate of tags (and probably overuse them). But I generally find them very useful. Fortunately, with the macOS we have the best of both worlds: unlimited hierarchical folders and unlimited (?) tags.

In Evernote I’m now on my 2nd or 3rd major tag reorganization. Use of tag prefixes is one of the best methods of organizing and using tags that I have seen.

Like any design/system, it takes some time to work out the kinks, and to get used to it, to develop the ever-popular muscle memory. Yes, it takes extra effort to assign tags, particularly in the beginning, but, IMO, it is well worth it, especially after you have most of your items tagged, and you’ve established a good tag naming convention.

It is always hard to find the time to learn a new something, be it a new language (SW or spoken), or a new system for organizing. I have seen posts by some that say they just don’t have (or want to spend) the time and effort to make tagging work, especially since they don’t immediately see the ROI.

I’ll use myself as an example. When I first encountered other Mac users who said they thought the best notes/files/scripts organization was using the macOS itself, with a few tools, I pretty much rejected that out-of-hand, thinking they just didn’t understand the benefits of some of the “great” note/snippet organizers out there. So, I trudged on another year trying to find the ultimate snippet manager.

Chris (@ccstone) got me really thinking about tags with his concept of “text tags”, which are just text keywords with an “@” prefix, like “@Finder”. Turns out using the “@” make it much more searchable because it eliminates other forms of similar words. And, you can use Spotlight to search for these text tags in both the script contents, and the file name.

I really liked that, and used it extensively for at least 6 months or so. Then it struck me: why not use actual macOS Tags?

So, I spent another 6 months using both (I know – I’m a glutton for punishment LOL) until I could determine which method I really wanted to use. I’ve now made that decision: macOS Tags as primary, but as a backup I include text tags in my script header. This is made very easy by a script.

My workflow is:

  1. Create/write a script
  2. Save it, and assign macOS tags
  3. Use my getTextTags script from the SD scripts menu to generate the text tags from the macOS tags just assigned to that script file.
  4. Paste it my new script header.

Takes longer to type and read it than to do it. LOL

Here’s one cool thing about macOS Tags: If I decide later to rename a Tag, it is very simple, and it immediately applies to all files with that tag. Obviously that does not work with text tags.

I should be clear about one thing: I make good use of hierarchical organization (folders) and cross-cutting categorization (tags). I store every script in folder that represents what to me is the primary category. Then I assign it tags that may cut across several other prime categories. My primary location for curated handlers is my personal script library. That is one area where macOS tags don’t help, so I have text tags for each handler. for example:

on doJavaScript(pBrowserName, pScriptStr) -- @JavaScript @Web @Browser   @KMLib
on getSelectionList(pItemTypeStr, pAppNameStr) -- @Selection @Path @Finder @PathFinder @Posix @Alias @KMLib
on createFolder(pPosixPath) --	@Folder @File @ASObjC
on padR(pSource, pTotalLen, pPadChars) -- @Strings @Pad
on getPOSIXPath(pAnyPath) -- @Path @Posix
on formatDateISO(pDate) -- @Date @ISO @Format @String

SD7 is great with code completion of handlers in your script lib, but what if you don’t remember the handler name? I’m working on a system now with either Typinator or Keyboard Maestro that allows me to search for handlers in my script lib using their text tags. I think Chris (@ccstone) has already implemented a similar system using Typinator.

Well, sorry to have gone on for so long about tags, but I hope some of you will find this discussion useful.

Please feel free to ask questions and challenge me about it, and of course I love suggestions for improvement.

2 Likes

That’s my opinion, for pragmatic reasons: third party tools eventually finish unsupported and you’re left with buggy software that you can’t do anything with and that you’ll eventually have to replace as the OS evolves. Using out of the box solutions first and then the fewest possible 3rd parties is the best possible way to keep a stable environment. Same for proprietary formats: I prefer application agnostic text files to anything else.

1 Like