pixelgeek Posted May 3, 2023 Share Posted May 3, 2023 Hi all I am working on correcting some issues in a workflow I have and while I was in there tinkering I thought that I would try to divorce the workflow from Safari. I found a command line call that will read the default browser and return it but I want to get a lot of data to make sure that I have as many browsers covered. The command is: defaults read ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure | awk -F'"' '/http;/{print window[(NR)-1]}{window[NR]=$2}' If you are running something other than Safari could you run this command and then paste the return here so I can gather as many browser IDs as possible? Or if someone knows of where there is a list of these apps? Thanks Link to comment
vitor Posted May 3, 2023 Share Posted May 3, 2023 That’s the bundle identifier of the app. You can get it for any app by running mdls -raw -name kMDItemCFBundleIdentifier /PATH/TO/APP, so by downloading them you’ll get what you seek without even having to take them out of the DMG. Alternative versions of browsers usually have predictable bundle identifiers. So the stable version of Brave is com.brave.Browser and the beta is com.brave.Browser.beta. Edge is com.microsoft.edgemac and the canary version is com.microsoft.edgemac.Canary. Vivaldi is com.vivaldi.Vivaldi. Chrome is com.google.Chrome and the canary version is com.google.Chrome.canary. Link to comment
Stephen_C Posted May 3, 2023 Share Posted May 3, 2023 Firefox is org.mozilla.firefox. Stephen Link to comment
pixelgeek Posted May 3, 2023 Author Share Posted May 3, 2023 Thanks That should cover most of them Link to comment
pixelgeek Posted May 3, 2023 Author Share Posted May 3, 2023 1 hour ago, Stephen_C said: Firefox is org.mozilla.firefox. Which is enough to test for and then put up a sad dialog as I don't think you can get any data from Firefox can you? Link to comment
pixelgeek Posted May 3, 2023 Author Share Posted May 3, 2023 2 hours ago, vitor said: That’s the bundle identifier of the app. You can get it for any app by running mdls -raw -name kMDItemCFBundleIdentifier /PATH/TO/APP I just wrote a quick Universal Action to run that for me. Thanks Link to comment
pixelgeek Posted May 4, 2023 Author Share Posted May 4, 2023 So I built a series of actions that I am going to add to my Create Obsidian Bookmark action. I will be using it as a prefab in that action. Currently it has a keyword trigger but that was just for testing. It runs a shell script to get the default browser's bundle ID. duti -x .html | sed -n '3p' | tr -d '\n' This uses duti to get the default app for .html files. That returns three lines of data Safari /System/Volumes/Preboot/Cryptexes/App/System/Applications/Safari.app com.apple.Safari I only need the last one so I use `sed` to get that and then `tr` to strip off the trailing line feed. This is split and then I save the last item as the browser name and use a conditional to select the appropriate Automation Task for each browser. I've tested it in Chrome, Vivaldi, Brave, Edge, Safari and Opera and it correctly tries to get the tab title and URL. Anyone interested in this? @vitor can I export a prefab? Link to comment
Stephen_C Posted May 4, 2023 Share Posted May 4, 2023 7 hours ago, pixelgeek said: Which is enough to test for and then put up a sad dialog as I don't think you can get any data from Firefox can you? Correct. I mentioned it only for completeness. Stephen Link to comment
vitor Posted May 4, 2023 Share Posted May 4, 2023 Instead of grabbing the default browser, I would recommend grabbing the frontmost app and then acting accordingly if it is a supported browser. You can’t really trust that the default app to open HTML files will be a web browser (think web developer using a code editor). I do think there could be improvements to this multiple browser handling. I have some ideas but nothing to share yet. Link to comment
pixelgeek Posted May 4, 2023 Author Share Posted May 4, 2023 How likely is it that someone would have an app set to open HTML files that wasn’t a browser? Maybe add the frontmost app as a fallback instead? Link to comment
pixelgeek Posted May 4, 2023 Author Share Posted May 4, 2023 8 hours ago, vitor said: Instead of grabbing the default browser, I would recommend grabbing the frontmost app and then acting accordingly I actually thought that it might be more likely that someone would have multiple browsers open and so in that case using the frontmost app makes more sense Link to comment
pixelgeek Posted May 4, 2023 Author Share Posted May 4, 2023 I now have it using the frontmost app. I just need to do some tests to make sure that the names returned from the Automation Task match the values I am branching from. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now