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
- Select one or more aliases or/and symlinks in the Finder
- 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:
- Convert all concerned symlinks to aliases.
- 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.
- Test one or two of the aliases to verify that they have been updated.
- 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.