[HN Gopher] Taking command of the Context Menu in macOS
       ___________________________________________________________________
        
       Taking command of the Context Menu in macOS
        
       Author : msephton
       Score  : 69 points
       Date   : 2024-07-30 16:20 UTC (6 hours ago)
        
 (HTM) web link (blog.gingerbeardman.com)
 (TXT) w3m dump (blog.gingerbeardman.com)
        
       | rkwz wrote:
       | > Submenu is optional
       | 
       | > Apply to multiple types (files or directories; can be as
       | granular as file extension)
       | 
       | > Show output (sometimes you want to see the results of the
       | command)
       | 
       | > Confirmation before running (if it's a potentially dangerous
       | operation)
       | 
       | Nit: The last 2 points are actually possible in Automator
       | 
       | Some examples:
       | 
       | * Remove PDF password: https://www.sheshbabu.com/posts/remove-
       | pdf-passwords-using-q...
       | 
       | * Summarize text with Ollama:
       | https://www.sheshbabu.com/posts/system-wide-text-summarizati...
        
         | msephton wrote:
         | Fair point! My memory is hazy :)
        
       | kelsey98765431 wrote:
       | I enjoy some cool macos tricks, but the bash substitution was
       | something I had never seen!
       | 
       | Very neat, I looked into it briefly and it looks like using
       | {@%.*} is not posix compliant, but a bashism. However the
       | substitution itself is posix compliant, so I may start using
       | something like this in my scripts. Need to look at this more, but
       | this is a heck of a lot less clunky than `echo | sed`... I need
       | to go read `info coreutils` more closely.....
        
         | msephton wrote:
         | ${@%.*} is valid in both bash (old macOS default shell) and zsh
         | (current macOS default shell).
        
       | jbverschoor wrote:
       | Don't invest in abandoned applications and frameworks
        
         | nerdjon wrote:
         | I assume you might be talking about the Mac app that has not
         | had an update since 2023.
         | 
         | But why do we consider that abandoned? It seems like the kind
         | of thing that if it works, why keep updating it? Now if it
         | broke in a new version of Mac and it wasnt updated, sure we
         | could call it that. But from what I can tell this is not the
         | case.
        
           | chrisandchris wrote:
           | He must be a web developer. If it isn't updated on Sundays or
           | reinvented every uneven month, it must be unusable.
           | 
           | /s
        
         | msephton wrote:
         | Which application or frameworks are you referring to? I've been
         | running this setup for well over a decade.
        
       | a1o wrote:
       | It's weird how hacky macOS feels compared to Linux, where you can
       | get a good idea on how things works due to openness and Windows,
       | due to the good documentation Microsoft offers. In macOS it
       | always feels like you have to be grateful about whatever is
       | allowed and depend on mysterious closed source software.
        
         | nerdjon wrote:
         | I am curious what about this you consider hacky?
         | 
         | Everything except for the last part of this is native
         | functionality built into Mac. Automator is an app every Mac
         | ships with and it natively has the ability to put things in
         | your Quick Actions, make folder actions, etc.
         | 
         | The only real hacky part of this is that it is stuck within the
         | "Quick Actions" menu instead of just being part of the dropdown
         | and this app addresses that. But thats a fairly small part of
         | this implementation.
        
           | therein wrote:
           | That's exactly what he is referring to. In Windows, you'd
           | either have something documenting that API (to add it in the
           | context menu, not under Quick Actions), or if it is
           | undocumented, you'd still have an idea where to look for it.
           | There would be some sort of API, you'd LoadLibrary, find the
           | symbol, call it with some arguments. Even undocumented, you
           | can kind of rely that it will be there later in some shape or
           | form.
           | 
           | In MacOS, it is really convoluted. Do I dynamically load some
           | bundle? What bundle? Likely they'll put it somewhere else
           | sometime soon.
           | 
           | Of course in principle, there is some API but the way that
           | Apple treats them is very different.
           | 
           | For example, I want to get how many fingers are touching the
           | trackpad right now and the current position of these touches.
           | There are all sorts of things like PinchControllers that need
           | to be initialized and they emit events etc., but nothing to
           | give you the current state of affairs or exactly what you
           | want.
        
             | nerdjon wrote:
             | I am confused, I feel like we are talking about different
             | things.
             | 
             | If you look at the page, the difference between the
             | official implementation and this app is that instead of it
             | being under "Quick Actions" in your context menu, it is
             | just right there.
             | 
             | It isnt like Apple doesn't give you a way to put something
             | in your context menu with Automator, they just put it
             | inside Quick Actions. You don't even need to use Automator,
             | just right click in finder, go to quick actions and click
             | customize.
             | 
             | Would it be great if I didnt need it to be stuck under
             | Quick Actions, I mean sure. But except for one minor change
             | (making something 1 less level deep in a menu) this entire
             | workflow is possible without any third party app or
             | "hacks".
             | 
             | Edit: If we want to talk about API's and other things sure.
             | But given the context of this article, I was assuming that
             | the OP was talking about the functionality presented in
             | this article which most of the implementation is Apple
             | provided tooling.
        
             | dlivingston wrote:
             | > it is undocumented, you'd still have an idea where to
             | look for it. There would be some sort of API, you'd
             | LoadLibrary, find the symbol, call it with some arguments.
             | Even undocumented, you can kind of rely that it will be
             | there later in some shape or form.
             | 
             | Is using undocumented APIs in Windows common? This sets off
             | my Spidey-sense hard.
        
               | nullindividual wrote:
               | Usage of the NT API isn't uncommon, but it is highly
               | discouraged.
        
         | frou_dh wrote:
         | If you've been a techy Mac user and don't know about Automator
         | then it's a you problem. It was evangelised quite heavily and
         | has been in its final form for a long time. These are its
         | twilight years as the new-ish Shortcuts system takes over.
        
           | mediumsmart wrote:
           | exactly. https://macosxautomation.com _thank you Sal
           | Soghoian_
        
           | msephton wrote:
           | I think it's worth celebrating users discovering new things.
           | We were all that user at one time.
        
             | frou_dh wrote:
             | On second thoughts, I think the person I replied to was
             | perhaps talking specifically about the (in)ability to put
             | things at the root of the menu. So I apologise if that was
             | the case.
        
         | fortran77 wrote:
         | I'm amazed at how hard it is to write a native desktop app in
         | MacOS! Macs didn't originally have a two-button mouse, so it
         | could be context menus are "hacky" because of their late
         | arrival.
        
       | serjester wrote:
       | I use this to easily convert files and some basic data munging
       | scripts - I'd be super curious what other people are doing.
        
         | msephton wrote:
         | At the bottom of the blog post I link my repo with actions
         | covering dozens of use cases.
        
       | nerdjon wrote:
       | I have recently been looking at how I can use some Mac native
       | tools to improve my workflow. Finally exploring tags and smart
       | folders for example.
       | 
       | I even built my own Mac app which sits in my menubar syncing tags
       | on project folders with the status of projects in a web app I
       | built. Even better that is synced with iCloud so I can access all
       | of those files and tags from my other devices.
       | 
       | I had not considered how else I could improve this situation with
       | context menu options, but now I want to explore how I could use
       | Automator to improve this setup even more.
        
         | msephton wrote:
         | Good work! Keep going with it. Power user status.
        
           | nerdjon wrote:
           | Its kinda funny, I have shown 2 people this tool so far.
           | 
           | One is another engineer, who we kinda laughed over a tendency
           | to spend an insane amount of time automating things that are
           | quick. Like adding a tag to a folder is quick, I just didnt
           | want to do it and things get out of sync.
           | 
           | But he also thought it was really cool and also did not
           | really know about tags until we started talking about this.
           | Kinda like me, he knew they were there but just never did
           | anything with it.
           | 
           | I also showed it to my partner who kinda just keeps laughing
           | every time he sees me glued to my laptop debugging this thing
           | and tweaking it.
           | 
           | It has honestly been a really fun project though. Trying to
           | keep things as native functionality as possible since the
           | entire point of this is to make it so I can more easily work
           | on a script or some other supporting document for a project
           | on my iPad or iPhone and once I get on my Mac everything will
           | just fall into place. I even made it so if I make a folder,
           | it will send the name of that folder to my web app as a new
           | project. (well the web app handles if its new or not, but
           | still).
           | 
           | My only real annoyances so far:
           | 
           | 1: Mac doesn't have the ability natively to automatically tag
           | all files in a folder that the tags of the parent folder. I
           | could script this, and I might. But I kinda wish I didn't
           | have too.
           | 
           | 2: Why is there no ability in Swift or a Mac app in general
           | to read the contents of a Pages file. Honestly this kinda
           | drives me insane. (I found a workaround by using a github
           | project to turn it into HTML, but that really should not be
           | necessary).
           | 
           | 3: I really wish I could make a smart folder that would show
           | me files based on the tags of the parent folder. This way I
           | could have 2 folders in different locations (one that syncs
           | with iCloud and one that syncs with my NAS with very
           | different data, but used in combination) and I could create a
           | smart folder with a single view of all of those files. But
           | this unfortunately seems impossible. (Edit: I guess I could
           | just automatically create symlinks, but a smart folder would
           | be so much cleaner)
        
             | NaOH wrote:
             | Sounds like we do similar organization, though I avoid Tags
             | and use Keywords, which I prefer primarily because they can
             | be embedded in many files types and can be more numerously
             | assigned. Regardless, for much of your work assigning Tags
             | and organizing files, have a look at Hazel for automating
             | these tasks. And yes, it can read the contents of Pages
             | files.
             | 
             | https://www.noodlesoft.com
        
               | nerdjon wrote:
               | I did briefly look at Hazel, I think at this point it
               | would likely be unnecessary.
               | 
               | I already have my app which has the custom code to work
               | with the API of my web app and set tags accordingly, at
               | that point it would honestly be trivial to have it go
               | through all of the subdirectories of a folder. I would be
               | quite surprised if I could have Hazel query an API, parse
               | the json, loop through it, and then tag based on the
               | various values.
               | 
               | Unless it solves my last issue? I did not think it did
               | when I looked at it, since that is more a limitation of
               | the smart folder filter than anything else.
               | 
               | That being said, I am confused by the difference between
               | keywords and tags? Since on Mac a tag can be put on any
               | file, folder, etc and doesn't care about the filetype. A
               | single tag can be on any number of files/folders and a
               | file/folder can have as many tags as I want (at least
               | seemingly, I have not seen a limit yet).
               | 
               | When you say keywords, are you just referring to using
               | certain... well keywords... in the filenames?
        
               | NaOH wrote:
               | >Unless it solves my last issue? I did not think it did
               | when I looked at it, since that is more a limitation of
               | the smart folder filter than anything else.
               | 
               | I don't believe Hazel will solve that last issue, but I
               | may be off about that and you're certainly more skilled
               | than I am.
               | 
               | >When you say keywords, are you just referring to using
               | certain... well keywords... in the filenames?
               | 
               | Keywords are not in the file name, they're embedded in a
               | file's metadata. For example, do a Print to PDF of a web
               | page, but in the last dialog where you can save, note
               | there's a Keyword field. Add something there that's
               | unique, then search on it with Spotlight. Have lots of
               | Keywords in use? Then Spotlight can use a keyword:[search
               | term] search, similar to how there are many other built-
               | in search queries.
               | 
               | My primary setup is to have Hazel monitor specific files
               | in specific folders looking for specific content within
               | those files. Based on the results, Hazel runs my
               | Automator Actions to embed the Keywords I want
               | (especially helpful for organizing my business files, but
               | I have plenty of other uses, like Hazel filing documents
               | based on the Keywords I added when using Print to PDF).
               | 
               | Ultimately, it sounds like you have a solid system
               | accomplishing most of what you want done. Certainly no
               | need to redo a viable setup. I was just hoping Hazel
               | could help with the Pages files, and maybe secondarily
               | some other parts of your process.
        
               | nerdjon wrote:
               | > Keywords are not in the file name, they're embedded in
               | a file's metadata. For example, do a Print to PDF of a
               | web page, but in the last dialog where you can save, note
               | there's a Keyword field. Add something there that's
               | unique, then search on it with Spotlight. Have lots of
               | Keywords in use? Then Spotlight can use a keyword:[search
               | term] search, similar to how there are many other built-
               | in search queries.
               | 
               | Ah I see now. If I understand properly, I can see the
               | value in this if you are setting a ton of keywords across
               | multiple systems, and you don't really want those to muck
               | up your finder window or list of tags.
               | 
               | Out of curiosity I went to the save as pdf, and tag is
               | also there. Honestly never noticed either being there.
               | 
               | I wonder why tags on Mac isn't just a layer built on top
               | of keywords if that is already there. Tags are even
               | available in smart folder filters.
               | 
               | Thanks for mentioning that, I think I might honestly use
               | both. Since I use some tags for project status. So things
               | like "research" "production" , etc etc. Things that are
               | actually valuable as tags on my sidebar to quickly filter
               | with. I even have colors associated with those to a quick
               | glance at my folder.
               | 
               | But being able to add a keyword for each project would
               | also be beneficial. It doesn't muck up my sidebar.
        
               | NaOH wrote:
               | Keywords are more widely available than may be obvious.
               | TextEdit accepts them, Preview in its Inspector panel,
               | Photoshop has a field, Word and Excel did (do?) in File >
               | Properties, and many others. I'm not near a Mac with
               | Pages so I can speak to that app. And just like Tags,
               | Keywords can be used with Smart Folders.
        
             | synthoidzeta wrote:
             | I'm not in front of my Mac but you could you run `cat`on a
             | Pages file?
        
               | msephton wrote:
               | Sadly not, a pages files is a sort of zip package
        
               | nerdjon wrote:
               | I am almost positive I tried that, and I want to say no.
               | 
               | The problem is that apparently the Pages file is just a
               | hidden bundle. But unlike apps, Final Cut Pro, and other
               | Mac bundles unless you go into Pages and change an
               | advanced setting per file it doesn't have the "Show
               | Package Contents" that the others do.
        
             | saagarjha wrote:
             | Have you tried using Spotlight to ask it what its indexable
             | contents is?
        
       | MaxikCZ wrote:
       | Is there a way to remove certain things from macos context menu?
       | Ideally to just hide them unless I hold Shift or some other
       | modifier?
        
         | msephton wrote:
         | What certain things?
         | 
         | Using ContextMenu.app (yes) Automator (no) standard macOS (no)
         | 
         | The key point is it only shows things in the right context:
         | every item can be run on the selection.
        
       | nullindividual wrote:
       | I've done this to strip Exif metadata from pictures using
       | Automator. Uses homebrew and the exiftool package.
       | 
       | Workflow receives current "image files" in "any application"
       | 
       | Image = Action
       | 
       | Run shell script:
       | 
       | Shell: /bin/zsh
       | 
       | Pass input: As argument                 for f in "$@"       do
       | /opt/homebrew/bin/exiftool -all= -tagsfromfile @ -ColorSpaceTags
       | -Orientation $f       done
       | 
       | ----
       | 
       | Will be under the Quick Actions menu.
       | 
       | I tried the same with Shortcuts, but I cannot get it to run from
       | the context menu, only within Shortcuts during testing. Maybe
       | something limiting shell command access from Shortcuts? Not sure.
        
         | msephton wrote:
         | nice use case!
        
         | lelandfe wrote:
         | The built in "Convert Image" Quick Action has a Strip Metadata
         | option
        
           | nullindividual wrote:
           | Thanks! However, it lacks a couple of things the Automator
           | script does. It wants to convert by default to JPEG instead
           | of keeping the source format, it requires interactivity, and
           | for some reason if I cancel the dialog, I can't get it to run
           | again without relaunching Finder (on 14.6).
        
             | lelandfe wrote:
             | Wow, can confirm that it silently dies if cancelled. Apple
             | these days, huh?
        
       | mettamage wrote:
       | I sometimes need a path name, so I have "Copy Path" in my context
       | menu
        
         | Tagbert wrote:
         | if you have the Path Bar visible in Finder you can right-click
         | on the folder name and choose "Copy 'X' as pathname". Works to
         | copy any parent folder name, too.
         | 
         | That's built-in and doesn't require any setup.
        
           | Doctor_Fegg wrote:
           | You can also drag the folder into Terminal to insert the path
           | at the current cursor, or cmd-drag it into Terminal to do a
           | `cd` to that path.
        
         | msephton wrote:
         | Hold down the Option key and the normal Copy changes to Copy as
         | Pathname (aka Full Path). I use this almost every day.
        
       | ctippett wrote:
       | BetterTouchTool also includes functionality to customise Finder's
       | context-menu. I was hoping Hammerspoon would have something
       | similar in their arsenal of APIs, but it doesn't look like they
       | do.
        
         | msephton wrote:
         | Nice tip, thanks!
        
       ___________________________________________________________________
       (page generated 2024-07-30 23:00 UTC)