Jump to content

Is there a workflow to allow me to create a bookmark folder in Safari?


Recommended Posts

I've tried searching but it seems a lot of the stuff broke when Safari updated. Any ideas? I just want to be able to add a folder: frequently I go to bookmark something and there isn't a folder for it so I just end up adding it to misc which gets lost. 

It's a pain to come out of the bookmark pane, go into bookmarks and create a nested folder, come out and then bookmark the page. 

 

Link to comment
  • 9 months later...
18 minutes ago, bongobong said:

If anyone's out there


A lack of reply doesn’t mean no one saw your request. Not everything is possible or doable with reasonable effort; we’re working within the constraints given by Safari and macOS.

 

It’s not a simple task, and Apple keeps pulling the rug. I can’t say how many person-years have been spent on figuring out solutions to bypass Apple’s imposed limitations, only for those to break in the following macOS release. But I can tell you my time is very much in that pool, and that predictably it is frustrating. You waste a lot of effort chasing a “maybe”.
 

On 2/1/2021 at 12:58 PM, bongobong said:

it seems a lot of the stuff broke when Safari updated.

 

Because a lot of those were hacky solutions. Is there a way to get them to work again? Maybe, but it will take a while for the first person to figure it out and publish it and the next person to come along and improve it and so it goes.
 

Maybe this time it’s easier (unlikely), but the point is we don’t know. This is why (well, one of the reasons) one should hold off on upgrading to the newest macOS version if you depend on hacks. Apple will take them away without half a thought.
 

You should consider directing your feedback at them. Use Feedback Assistant and ask for better tools to manage Safari, in this case ways to create bookmark directories programmatically via AppleScript or Shortcuts.

 

Alternatively, if you find a command-line solution which works we can help you integrate it into Alfred.

Link to comment
  • 5 months later...

I use Firefox while docked and Safari undocked (to save battery), and I was bothered that it was so difficult to sync bookmarks between browsers. Anyway I figured I'd use Safari as my "single source" bookmark system. Safari was an easy choice because it works well with Alfred and I can use Alfred to search and launch Safari bookmarks into my current default browser anyway (I use another workflow to change default browser instantly).

Anyway, that's the background. I made a GUI script to take the URL from the front window, open it in Safari and then bookmark to a specified folder. If the folder doesn't exist it will create one at the root (if it finds a nested folder it will target that). If Safari is already open it will just take that URL and proceed. It's a bit "hacky" because it uses the GUI and you'll see a few popups flash for a second. It seems to work very well though.

If you're interested I can make the script more "public friendly" and share it. I've never shared an Alfred workflow so don't expect something fantastic.

Ideally I'd write an application which could make edits to the Safari bookmark files in the system library without the user seeing anything change on screen. After a quick look at what's involved it's a bit beyond me at this stage! I could probably manage it, but it would take a long time. 

At any rate, what I have at the moment should do what you need it to do and it's snappy enough. 

Edited by Craigers
Link to comment
9 hours ago, Craigers said:

I use Firefox while docked and Safari undocked (to save battery), and I was bothered that it was so difficult to sync bookmarks between browsers. Anyway I figured I'd use Safari as my "single source" bookmark system. Safari was an easy choice because it works well with Alfred and I can use Alfred to search and launch Safari bookmarks into my current default browser anyway (I use another workflow to change default browser instantly).

Anyway, that's the background. I made a GUI script to take the URL from the front window, open it in Safari and then bookmark to a specified folder. If the folder doesn't exist it will create one at the root (if it finds a nested folder it will target that). If Safari is already open it will just take that URL and proceed. It's a bit "hacky" because it uses the GUI and you'll see a few popups flash for a second. It seems to work very well though.

If you're interested I can make the script more "public friendly" and share it. I've never shared an Alfred workflow so don't expect something fantastic.

Ideally I'd write an application which could make edits to the Safari bookmark files in the system library without the user seeing anything change on screen. After a quick look at what's involved it's a bit beyond me at this stage! I could probably manage it, but it would take a long time. 

At any rate, what I have at the moment should do what you need it to do and it's snappy enough. 

Wow that sounds like EXACTLY what I want. 

Will it auto-fill a bookmark folder as i start typing? Else I could see myself ending up with a bunch of bookmark folders; "Forum" & "Forums" & "Forum Stuff" etc. 

 

Yes please do share it. It would be amazing. I'm glad you had the same problem with Safari I did!

 

Link to comment
On 4/26/2022 at 10:30 PM, bongobong said:

Wow that sounds like EXACTLY what I want. 

Will it auto-fill a bookmark folder as i start typing? Else I could see myself ending up with a bunch of bookmark folders; "Forum" & "Forums" & "Forum Stuff" etc. 

 

Yes please do share it. It would be amazing. I'm glad you had the same problem with Safari I did!

 


Ok, I'll share soon. Honestly don't expect too much, no auto-fill at all - I might look at that in the future. It's what you call GUI scripting (using AppleScript) so it's only actions you can do manually with your mouse and keyboard anyway (except it's performed super fast). It's not "smart" and nothing feeds back into Alfred. I suppose I could generate a list of folders and feed that back... but I'm not sure I want to put too much effort into what will always be a hacky solution.  

 

If I'm going to do it "right" I'd want to do it fully right. The main reason for this workflow was to bookmark a Firefox page into Safari. I really don't want to have bookmarks spread across different browsers. If you're in Firefox the script does a bit more you see... it copies the URL, opens Safari, loads URL, stops the page load, bookmarks into folder, closes safari tab and then returns to Firefox.


Using this workflow in Safari alone is useful... but not all that much faster than cmd+d and some mouse clicks. If you're a fast typist though - anything through text command is generally better I guess. It's a bit easier to create folders I guess too.

Edited by Craigers
Link to comment

Here is the workflow:
https://github.com/Craig-Stowers/alfred-workflows/raw/main/BookmarkToFolder/Bookmark to Folder.alfredworkflow

 

Remember it's a GUI script so you just have to not touch anything while the process is happening. If the folder already exists it's much faster (the folder creation process is a bit convoluted as you'll see!).

If Apple changes the Safari GUI there is every chance it breaks too. I've only tested on my new MacBook Pro 14". The thing with GUI scripting is you have to allow time for events to occur before triggering the next action. I might have made the timings a bit too quick, but that's easy to fix. Where possible I've programmed the script to wait until the state of the application is a certain way before moving on which should allow for slower machines. I'm a little worried this could backfire and get stuck  (for instance if the active app changes halfway through the process).  Alfred should kill any process that gets stuck though. 

There is probably some more professional way to plug into the Safari bookmark system, but I'm not aware of it. Sometimes the only way to automate these things is to hijack the human interface Apple provides. If you find a better workflow please let me know :). End of the day, this is basic and hacky, but it's still very useful for me at least. 

Once you've tested, and I've added support for other browsers, I'll post in the "Share your Workflow" forum. 

Edited by Craigers
Link to comment

no problem. 

Sorry you'll have to manually make a nested folder, or just drag the folders around later after you've created them. If you're saving to an existing nested folder it should find it (but beware it will probably only place bookmark in the first folder of that name if you have duplicate names). Just make sure sub folders don't clash I guess (shouldn't be that much of a problem).


I really don't have much control... all the script does is trigger existing functions in Safari - for instance the "Add Bookmark Folder" menu item which adds a folder to the root level. I can't really do much about adding nested folders without doing some pretty extreme GUI scripting. GUI scripting should really be reserved for pretty basic things though.
One day if I actually figure out how to edit the Safari bookmarks without even using Safari GUI, I'll let you know. I can't seem to find any help out there though. Not sure if Apple have a friendly API for this kind of thing. 

 

If I get really bored one day, I might see what I can do with nested folders.

Edited by Craigers
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...