Simple alfred/applescript to get hooks to multiple items

Hello Hook-people (hookers doesn’t sound right),

I’m trying to work around a hook limitation where one can only get the hook to a single item at a time.
I figured It’d be simple to use alfred/applescript to write something where I just select a bunch of finder items and then execute the applescrupt using Alfred’s file-action. It ought to be simple I think, but I’m apparently not very good with applescript. Instead of a link to each item, I get the files themselves when I paste into another document. I’m sure it’s something obvious, but I’m not an expert with Hook either.

Thanks for any insight,
Carl

on alfred_script(q)

set theLinks to “”
set selectedFiles to “{query}”

repeat with afile in selectedFiles
tell application “Finder”
set filePath to POSIX path of (aFile as alias)
set fileAddress to “file://” & filePath
set fileURL to URL of afile
set fileName to name of aFile

    tell application "Hook"
        set hookBookmark to (make bookmark with properties {address:fileURL, name:fileName})
        set theLinks to theLinks & address of hookBookmark & "<br />"
	end tell

end tell

end repeat

set the clipboard to theLinks

end alfred_script

1 Like

Hi Carl, take a look at A Hook CLI for Terminal goodness - Showcases and Use Cases - Hook Productivity Forum.

2 Likes

See @ttscoff 's “Scripts and Services for Hook” and this spin-off for meshing Safari tabs.

1 Like

Thank you for the ideas @hanspe and @capcrime. I tried modifying @ttscoff 's scripts to make my simple applescript to make hooks to multiple files, but still no joy. To be clear, I think what I’m trying to do is much more basic than what those scripts are doing. I know that hook’s real power is in making hooks between files, but for now, I just use it for making permanent links to various items that I paste into my own project notebooks. So I’m just trying to loop over a bunch of finder-selected files, create hook links for each one, and then concatenate those hook links into the clipboard.

Here’s what I have so far. It runs, but the clipboard seems to always contain the files themselves, not the text of the hook deeplinks.

I’ve tried replacing “address” with “name” and “posixPath”

Thank you so much for having taken the time to reply to my initial inquiry.

on alfred_script(q)
set theLinks to “”
set _files to “{query}”
repeat with _file in _files
tell application “Hook”
set x to (percent encode POSIX path of (_file as string))
set _src to make bookmark with data x
set theLinks to theLinks & address of _src & “

end tell
end repeat
set the clipboard to theLinks
end alfred_script

I was able to get the Hook link on the clipboard for one file using Applescript. However, I could not get AppleScript to loop through a selection of multiple files and concatenate the links into a list for some reason. Could not figure out how to append to the relevant variable. Very frustrating.

Fortunately, I was able to execute your idea using Keyboard Maestro, which has an easy to use append variable function. This macro will loop through a multi-item selection in Finder and produce a list of Hook links, with a prompt to copy to clipboard. I am not an Alfred user but I’m sure there is a way for Alfred to call this macro from KM.

Copy Hook Link(s).kmmacros

Thanks for making the effort to get this to work. I thought I was going crazy, so it’s some comfort that you saw the same issue. I’ve written a fair number of Alfred workflows, but they’ve all been simple, so I’m not sure what the equivalent would be for Alfred. Maybe some Alfred expert can chime in. Thanks again.

1 Like

I strongly recommend Keyboard Maestro. I use Launchbar instead of Alfred but I need KM for my most useful and frequently used automations. I can use LB to fire a KM macro via Applescript. I’m sure Alfred can do the same.

1 Like

OK, I was so desperate to get this thing working, I jumped into KM. Looks good… we’ll see if it can coexist peacefully with Alfred.

I made a small edit to your script so that the resulting links are markdown compatible and can be pasted directly into something like Craft (which I highly recommend).

2 Likes