Make Symlink in AppleScript
Make Symlink in AppleScript
- Subject: Make Symlink in AppleScript
- From: iKel via AppleScript-Users <email@hidden>
- Date: Fri, 15 May 2020 19:34:25 -0500
I apologize in advance for my delay in response, but just wanted to give a
shout out to those who helped me on this.
Clark,
Your advice really helped. I was able to figure out after I executed it
in Terminal. Setting the variable as the entire shell command line is a great
practice to get into! Thanks for the direction. I made a rudimentary script,
but it’s a start. Again, I appreciate it.
Toto,
I appreciate your advice. I am still getting the grasp of handlers. So,
I appreciate the link; I have added to my desktop to peruse through it. Thanks
for the suggestion of using 'on open’ rather than ‘in run’. I now have a
working script. Thanks again!
Yvan,
I appreciate your script. I also went through your script and
translated the French because I am weird like that and wanted to better
understand the script in its entirety and I just like languages so I wanted to
learn new words. Of course, I did this with translator so it may not be 100%
accurate, so feel free to correct me if I am wrong.
I unfortunately get this error message: -1708 : NSFileManager doesn’t
understand the “defaultManager” message. I am not sure if I just haven’t copied
it incorrectly but I posted the code below, if you have time, any help would be
much appreciated! Thanks as always!
So, I have now three working scripts and have learned more and have gained
various techniques to utilize. Thanks so much!
best regards
(*
#+-+-+-+-+-+
Exécuter ce script ou déposer l'cône d'un fichier
sur son icône (script enreigistré en tant qu'application)
crée sur le bureau un lien symbolique vers le fichier.
Save the script as Application on the Desktop.
Drag and drop a file's icon on the script's icon
will create on the Desktop a symlink to the file.
#+-+-+-+-+-+
*)
#=====
#lignes exécutés si on double clique l'icône du script
#lines executed if we double click the script icon
(*
note: 'du' in French means something entirely different and is not to be
confused with the German word for the singular, informal usage of ‘you’
*)
on run
if my parle_anglais() then
--'parle anglais' means 'speak English'
"Choose a file ?"
else
"Choisir un fichier ?"
--means choose a file
end if
set _ to choose file with prompt result
my TraiteLeFichier(_)
--process file
end run
#=====
on open sel # sel contient une list d'alias des élélements
--cotains a list of element aliases
#qu'on a déposés sur l'cône du script (la sélection)
-- that we placed on the script icon (the selection)
my TraiteLeFichier(item 1 in sel)
--process file
end open # fin 2
#=====
on TraiteLeFichier(zefile)
--process file
try
set leChemin to POSIX path of zefile
--leChemin translates to "the path"
--zefile ??
tell application "System Events" to set fName to name of zefile
#ADDED
set path2link to (path to desktop as text) & fName
my createSymlink:(POSIX path of path2link) pointingTo:leChemin
on error MsgErr number NroErr
if NroErr is not -128 then
beep 2
if my parle_anglais() then
"Oops"
else
"Vu"
--got it or understood or seen as in Déjà Vu
(already seen)?
end if
tell application "SystemUIServer" to ¬
display dialog "" & NroErr & " : " & MsgErr
with icon 0 ¬
buttons {result} giving up after 20
end if
return
end try
end TraiteLeFichier
#=====
on parle_anglais()
return (do shell script "defaults read 'Apple Global Domain'
AppleLocale") does not start with "fr_"
end parle_anglais
#=====
on createSymlink:newPath pointingTo:targetPath
log newPath
log targetPath
set fileManager to current application's NSFileManager's
defaultManager()
set theResult to fileManager's createSymbolicLinkAtPath:newPath
withDestinationPath:targetPath |error|:(missing value)
return (theResult as boolean)
end createSymlink:pointingTo:
#=====
#[/SCRIPT]
Live your life as an exclamation rather than an explanation. -Sir Isaac Newton
iKel
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden