![]() |
How to create a Finder alias from shell script?
How do I create a Finder alias (which is not the same as a Symbolic or Hard Link) to a file from a shell script? (IE - the same thing as Ctrl-clicking a file and selecting "Make Alias")
I know I can set a file's attribute using SetFile -aA to tell Finder it's an alias file, but how do I define what it's an alias to? |
hmm, well, i don't think there is a command to do this; craft a finder-style alias from the shell.
could possibly be done with osascript ? |
This appears to work:
Code:
osascript -e 'tell application "Finder" to make alias file to alias "path:to:original file" at desktop' |
Quote:
osascript -e 'tell application "Finder" to make alias file to alias "source folder:${MyDirectory[x]}:folder" at "target folder:${MyDirectory[x]}:My Package.app:Contents:Resources"' It just doesn't seem to work, no matter how I write the paths (with / instead of :, escaping the quotes, using "folder x of folder y of folder z", etc.) I can create the target on the desktop and MvMac it, so things are working. |
I reckon you'll need to convert your variables to something that Finder understands. I doubt that it knows what '${MyDirectory[x]}' means (I don't know either! :p).
-- Rob (the non-Unix one) |
single-quoted strings ( 'foo' ) turn off variable interpolation in the shell, so the variable reference in 'blah ${foo} blah' is just that string of characters.
you need to craft the scriptage in double-quotes so that the variable references ( ${foo} ) are resolved. use a 'here doc' ; here's a sample ... Code:
osascript <<_eof |
That does seem to solve the source problems. I still can't seem to create the alias inside a package, it just throws "Can't get alias file" errors.
|
Why does it have to be a finder alias versus a symlink?
v |
The short of it is, we're supporting someone elses code that requires it to be a finder link.
Mucho frustrating. |
I just tested a simple AppleScript script and it is possible to create an alias within a package. What type of paths are you passing to the Finder. It understands only colon delimited paths.
Code:
path:to:fileCode:
set foo to "/usr/bin/" |
script
Here's a Bash script for making Finder-style aliases:
Code:
#!/bin/shmake_alias myfile ~/Desktop |
Aha! It's not the target that's killing it, it's the source. I'm trying to make an alias of a folder and that's what's not working. Changing the file to folder in the script fixed that.
Thanks for all the help gang! |
Quote:
|
thanks
I just wanted to say thanks for the shell script. It solved a problem I had too, where creating an alias from the finder was not possible.
|
I have modified the above 'make_alias' script so that it works with ".app" files. (These are folders according to Unix, but we need to treat them as files when making Finder aliases to them.)
|
great script, but how can it be modified to set a .icns file to be displayed on the alias?
thanks! |
I agree. Haynie's a genius. Great script.
I copied the resource fork to a short cut and that worked. Code:
mkalias ~/Pictures/..../A.jpg ~/Desktop1) This didn't work when I copied compass.icns from Safari.app. 2) (shock horror). I had to modify haynie's $srcPath variables to "${srcPath}" to get the script to work on files with spaces in their names. 3) Beware of sips --addIcon on Leopard (spoils Coverflow, because Finder uses the low res icon). I've got a fix if anybody's interested (this is way off subject). |
Quote:
I'm trying t make a list of alises to image folders so that iTunes can synch them to my AppleTV... and it doesn't seem to follow symbolic links. :-/ ----- Never mind... I mis-read. I see your script DOES accept folder. It'd be cool if I could pass the filename of the alias instead of it's enclosing folder. |
Shoot!
Turns out iTunes' AppleTV photo synch won't follow aliases EITHER! So now I'm not sure how to grab (selected) photos that are spread all around my hard drive. :-/ |
Finder Smart Folder, then drag & drop selection(s) from the results?
|
Wow! That's a great idea!
I'll try that when I'm back on my Mac. (Must use WinDoze for Work :-( ) |
I'm so gonna pull my hair out!
When you browse to a Smart Folder, it's grey'd out, so you can't select it. So where exactly would I "drag and drop these"? |
Smart Folders allow me to select items, both in the Finder and in iTunes. If you create a Smart Folder in the Finder, you should be able to drag & drop movies into iTunes, unless they're a format that isn't supported.
Maybe if you describe exactly what steps you're taking and where the problem occurs we can figure out what's going wrong. |
I'll point out that one of the canned sidebar searches that the Finder offers is "all images". Go to Finder preferences, Sidebar tab, third from the bottom. this will gather all the images on your hard drive, and you can move them where and as you like.
|
| All times are GMT -5. The time now is 06:11 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.