• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Make Symlink in AppleScript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make Symlink in AppleScript


  • Subject: Re: Make Symlink in AppleScript
  • From: Yvan KOENIG via AppleScript-Users <email@hidden>
  • Date: Sat, 2 May 2020 21:45:34 +0200

Here is an old script from my archives.

use AppleScript version "2.4"
use framework "Foundation"
use scripting additions


#[SCRIPT crée lien symbolique]
(*
# +-+-+-+-+-+
Exécuter ce script ou déposer l'icône d'un fichier
sur son icône (script enregistré 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.

Yvan KOENIG (VALLAURIS, France)
5 janvier 2014
2014/11/28 use a library

# +-+-+-+-+-+
*)


#=====

# lignes exécutées si on double clique l'icône du script
on run
        if my parle_anglais() then
                "Choose a file …"
        else
                "Choisir un fichier …"
        end if
        set _ to choose file with prompt result
        my TraiteLeFichier(_)
end run

#=====

on open sel # sel contient une liste d'alias des éléments
        # qu'on a déposés sur l'icône du script (la sélection)
        my TraiteLeFichier(item 1 in sel)
end open # fin 2

#=====

on TraiteLeFichier(zefile)
        try
                set leChemin to POSIX path of 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 "
                        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]


Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 2
mai 2020 21:45:29
 _______________________________________________
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

References: 
 >Make Symlink in AppleScript (From: iKel via AppleScript-Users <email@hidden>)

  • Prev by Date: Make Symlink in AppleScript
  • Next by Date: Re: Make Symlink in AppleScript
  • Previous by thread: Make Symlink in AppleScript
  • Next by thread: Re: Make Symlink in AppleScript
  • Index(es):
    • Date
    • Thread