Alias/Symlink Converter

link
tools
finder
files_folders
applescript

#1

Another little macro for the Finder.

>>> Update 2017-03-31, see bottom of the post.

What it does

It replaces selected aliases with absolute symlinks, and selected symlinks with aliases.

How to

  1. Select one or more aliases or/and symlinks in the Finder
  2. Run the macro
  • Symlinks will become aliases and aliases will become symlinks. The names will be the same as before.

Error Handling

  • If the script encounters broken aliases or links (that is, the target cannot be found), it will give you a popup at the end, telling you how many of the processed aliases/links are broken.
    In addition it will append “.—broken!” to the names of those files.

  • If the script encounters other errors (e.g. a locked alias/link) it will pop up a warning and let you choose if you want to continue processing the remaining aliases/links.

Notes

You can use the macro also if you have to rename or move the target files of some symlinks:

  1. Convert all concerned symlinks to aliases.
  2. Since aliases are tracking name and path changes of the target file (at least in most cases!) you can now move or rename the target files.
  3. Test one or two of the aliases to verify that they have been updated.
  4. Convert the aliases back to symlinks.

Alias:Symlink Converter [ver 0.9.5].kmmacros (7.5 KB)


Update 31 Mar 2017, 17:08 Z

Ver 0.9.2

The script can now convert aliases to relative symlinks

Example:

Absolute symlink:

Relative symlink [1]:

To get relative symlinks just hold down the Control key while the script is launching.

The most convenient way to have the Control key down at script launch is to assign a second macro hotkey that involves the Control key. See the updated screenshot above.

So – with the example hotkeys from the screenshot – you launch the macro with…

  • F1 to get absolute symlinks (the default)

  • F1 to get relative symlinks

Alternatively, if you don’t want to spend a second hotkey, press and hold the Control key immediately after the hotkey, or add a Pause action (e.g. 0.5s) at the top of the macro, so that you have enough time to press the Control key after macro launch.

Just make sure that the normal macro hotkey doesn’t contain the Control key, otherwise you risk to get always relative links.

If you have no need for rel. symlinks, you can also comment out or delete the corresponding block at the beginning of the script. (It has an explanatory comment.)

Notes

  • When converting symlinks to aliases it doesn’t matter if the Control key is pressed or not.
  • You can change the modifier key for rel. symlinks in the script (the options are explained there).
  • The script is fully portable, you can also launch it from the Scripts menulet, via Service workflow, via LaunchBar, etc.

[1] Relative symlinks are necessary when you have to move around the target files together with the symlinks.
A typical use-case would be: you have a project folder with various subfolders; you are linking some documents or pictures from subfolder A to subfolder B.
With relative symlinks you can freely move around the entire project folder, or copy it to another disk. Absolute symlinks would break in that case.


#2

This is great, Tom. Thanks! What might a use-case be for having absolute symlink over relative?


#3

I think, in most cases, what you want are absolute links, because you can freely move them, or move the containing folder(s) — as long as you don’t move the target file or otherwise change the path of the target file. (The link has stored the path of the target as absolute path, always beginning with a slash / See the terminal screenshots in the post above.)

You can’t do this with rel. links. You have to you move link and target together, as described in the footnote above, because the link stores the target’s path as relative to itself (to the link). But you can freely remove/rename the folder(s) that contain both the rel. link & target.

See the very good figurative explanation in this post. (Or read the whole thread for more explanations.)


#4

I had to sign up just to say thanks for making this. It has helped me out big time. I have more than a thousand symlinks that I have been converting manually but this is making the rest of the job a breeze. Awesome work.


#5

Tom, I too have used it to convert thousands (110,000+) of aliases to symlinks (and back again) in order to move directories of aliases from one external drive to another. This macro has greatly simplified the process. Thank you for the brilliant work.