{"id":828,"date":"2020-06-05T09:31:01","date_gmt":"2020-06-05T16:31:01","guid":{"rendered":"http:\/\/10.0.1.201\/?p=828"},"modified":"2025-12-01T12:15:37","modified_gmt":"2025-12-01T19:15:37","slug":"symlink-creation-in-the-finder-applescript","status":"publish","type":"post","link":"https:\/\/strawhousepig.net\/wordpress\/2020\/06\/05\/symlink-creation-in-the-finder-applescript\/","title":{"rendered":"Symlink creation in the Finder AppleScript"},"content":{"rendered":"\n<p>This script can be run from the script menuextra, or also as an app or droplet if saved as a app. Has not been tested for use beyond OS X 10.6.8 (not sure which useless, silly nickname this version has &#8211; still cats at this point, though &#8211; I&#8217;ve never seen the point in memorizing that garbage).<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>What it does is ask for files, or as an app use files dropped onto it, as sources to create symbolic link targets at a folder of the users choosing.<\/p>\n\n\n\n<p>Including a non-generic (or less generic) icon since it&#8217;s nice to have one when these sorts of droplets are placed in the toolbar of Finder windows. To place in the app package, right click (control click) on the application in the Finder and select &#8220;Show package contents&#8221; from the pop-up menu. In that window navigate to Contents:Resources, duplicate the original icon file (droplet.icns), and then place the unzipped version of the below icon file into the Resources folder.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"256\" height=\"256\" src=\"https:\/\/strawhousepig.net\/wordpress\/wp-content\/uploads\/2020\/06\/Symlinker.png\" alt=\"\" class=\"wp-image-1086\" style=\"width:94px;height:auto\" srcset=\"https:\/\/strawhousepig.net\/wordpress\/wp-content\/uploads\/2020\/06\/Symlinker.png 256w, https:\/\/strawhousepig.net\/wordpress\/wp-content\/uploads\/2020\/06\/Symlinker-150x150.png 150w\" sizes=\"auto, (max-width: 256px) 100vw, 256px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-4f0dbd61-92ac-4c02-a28f-4070085cfd08\" href=\"https:\/\/strawhousepig.net\/wordpress\/wp-content\/uploads\/2020\/06\/Symlinker-droplet.icns_.zip\">Symlinker-droplet.icns<\/a><a href=\"https:\/\/strawhousepig.net\/wordpress\/wp-content\/uploads\/2020\/06\/Symlinker-droplet.icns_.zip\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-4f0dbd61-92ac-4c02-a28f-4070085cfd08\">Download<\/a><\/div>\n\n\n\n<p><br> FYI, I did not do a 512 pixel version. <ins datetime=\"2020-06-22T23:19:03+00:00\">[UPDATE] New sexier icon, created with Affinity Photo (and Icon Composer of course).<\/ins><br> <ins datetime=\"2020-06-30T20:00:57+00:00\">[UPDATE] New sexier script. Will either prompt for source files or run on items selected in the Finder. Also logs symlinks created.<\/ins><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>(*\nhttp:&#47;&#47;strawhousepig.net\/\n\nLogs date, time, and path of symlinks created into ~\/Library\/Logs\/symlinker.log\nNot that I've ever hit a return button without being certain of where I was at.\nThis log does not have a rotation mechanism. Could be added to the periodicals, though.\n\nThere is a 'behavior' setting below.\n\nIt should be noted that dropping a large amount of files and attempting to link into their\nsource directory will result in an equally large amount of error dialogs unless user cancels.\nYou could move the target check to before the repeat, but then you need another\nrepeat that does the same as in the repeat already here, so *meh*.\n\nModified from- https:\/\/www.macworld.com\/article\/1058177\/symboliclinks.html\n\n*)\n-- This setting decides the initial behavior of this script. Set to either \"auto\" or \"prompt\"\n-- auto - One less step, but your Finder skills need to be up top. Runs immediately on items selected in the Finder where ever it has focus. It is also the only way this script (in its current form) will symlink a directory.\n-- prompt - Safer due to having the extra step of choosing in script which files to run on.\n\nproperty symlinker_behavior : \"auto\"\n\non run\n\tif symlinker_behavior is \"prompt\" then\n\t\ttell application \"Finder\"\n\t\t\ttry\n\t\t\t\tset cwd to folder of window 1\n\t\t\ton error\n\t\t\t\tset cwd to home\n\t\t\tend try\n\t\tend tell\n\t\topen {choose file with prompt \u00ac\n\t\t\t\"Choose a source file to create a symbolic link:\" default location cwd as alias with invisibles and multiple selections allowed}\n\telse if symlinker_behavior is \"auto\" then\n\t\ttell application \"Finder\" to set _files to (selection as list)\n\t\topen (_files)\n\telse\n\t\tdisplay alert \"Erroneous setting in main.scrpt.\" as warning\n\tend if\nend run\non open the_files\n\tset dest_dir to choose folder with prompt \"Select a target directory.\" with invisibles\n\trepeat with source in the_files\n\t\ttry\n\t\t\tset source_path to POSIX path of (source as alias)\n\t\t\tset target_path to POSIX path of dest_dir &amp; name of (info for (source as alias))\n\t\t\tif target_path is not source_path then\n\t\t\t\tif source_path ends with \"\/\" then set source_path to text 1 thru -2 of source_path\n\t\t\t\tdo shell script \"ln -s \" &amp; quoted form of source_path &amp; \" \" &amp; quoted form of target_path\n\t\t\t\tdo shell script \"echo `date \\\"+%Y-%m-%d %H:%M:%S\\\"`' \" &amp; target_path &amp; \"' >> ~\/Library\/Logs\/symlinker.log\"\n\t\t\telse\n\t\t\t\tdisplay dialog \"Cannot place links to source in source directory.\" with icon 0\n\t\t\tend if\n\t\ton error theErr\n\t\t\tif theErr is not \"User canceled.\" then display dialog theErr\n\t\tend try\n\tend repeat\nend open<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This script can be run from the script menuextra, or also as an app or droplet if saved as a app. Has not been tested for use beyond OS X 10.6.8 (not sure which useless, silly nickname this version has &#8211; still cats at this point, though &#8211; I&#8217;ve never seen the point in memorizing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[10,23,24,28],"class_list":["post-828","post","type-post","status-publish","format-standard","hentry","category-code","tag-applescript-2","tag-macintosh","tag-macos","tag-os-x"],"_links":{"self":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts\/828","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/comments?post=828"}],"version-history":[{"count":2,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts\/828\/revisions"}],"predecessor-version":[{"id":1088,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts\/828\/revisions\/1088"}],"wp:attachment":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/media?parent=828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/categories?post=828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/tags?post=828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}