web-dev-qa-db-fra.com

Créer un lien symbolique dans le Finder de Mac OS X

Existe-t-il un moyen d'obtenir les mêmes fonctionnalités que la commande unix ln -s dans le Finder de Mac OS X (OS 10.5)? Je souhaite pouvoir créer des liens symboliques tout en travaillant dans les fenêtres du Finder sans ouvrir le terminal.

Notez que la commande Make Alias dans le Finder n’est pas ce que je veux car ces alias ne peuvent pas être parcourus dans le terminal (mais les liens créés avec ln -s peuvent être parcourus à la fois par le terminal et le Finder).

39
Michael Schneider

Qu'en est-il de la création de liens symboliques dans le Finder via AppleScript ?

Voici le script le plus pertinent dans ce lien:

on run
    open {choose file with Prompt "Choose a file to create a symbolic link:" without invisibles}
end run

on open the_files
    repeat with i from 1 to (count the_files)
        try
            set posix_path to POSIX path of (item i of the_files)
            if posix_path ends with "/" then set posix_path to text 1 thru -2 of posix_path
            do Shell script "ln -s " & quoted form of posix_path & " " & quoted form of (posix_path & ".sym")
        end try
    end repeat
end open

Il vous suffit de le coller dans AppleScript Editoret de l'enregistrer sous une application . Vous pouvez ensuite le faire glisser sur la barre d'outils du Finderou le lier sur le dock .

16
nuc

SymbolicLinker fera exactement ce que vous cherchez, et c'est gratuit.

alt text

26
arathorn

Un pomme script au lien fourni par l'utilisateur nuc a répondu à ma question. Voici le manuscrit de pomme reproduit au cas où ce lien disparaîtrait.

J'ai préféré le script donné par le commentateur jonn8n, qui était également reproduit sous la forme de l'article de Macworld .

on run
    open {choose file with Prompt ¬
        "Choose a file to create a symbolic link:" without invisibles}
end run
on open the_files
    repeat with i from 1 to (count the_files)
        try
            set posix_path to POSIX path of (item i of the_files)
            if posix_path ends with "/" then set posix_path to ¬
                text 1 thru -2 of posix_path
            do Shell script "ln -s " & quoted form of posix_path ¬
                & " " & quoted form of (posix_path & ".sym")
        end try
    end repeat
end open

J'ai enregistré ceci en tant qu'application à l'aide de Script Editor et j'ai fait glisser l'application dans la barre latérale du Finder afin que je puisse maintenant créer des liens symboliques en faisant glisser des fichiers ou des dossiers sur l'icône de l'application.

2
Michael Schneider

Path Finder ajoute ceci à votre Finder et ajoute beaucoup plus de fonctionnalités.

1
Khaled Kammar

En outre, dans Snow Leopard où SymbolicLinker ne fonctionne pas, vous pouvez créer un service avec Automator pour exécuter la commande Terminal ou AppleScript pour créer un lien symbolique.

0
beiju

Un autre AS:

tell application "Finder"
    repeat with f in (get selection)
        set p to POSIX path of (f as text)
        set p2 to POSIX path of (desktop as text) & name of f
        do Shell script "ln -s " & quoted form of p & " " & quoted form of p2
    end repeat
end tell
0
Lri

Une amélioration possible de ce script serait de changer le gestionnaire d'exécution pour utiliser les fichiers actuellement sélectionnés à partir du Finder, comme suit:

on run
    tell application "Finder" to set sel to selection
    open sel
end run
on open the_files
    repeat with i from 1 to (count the_files)
        try
            set posix_path to POSIX path of (item i of the_files as alias)
            if posix_path ends with "/" then set posix_path to ¬
                text 1 thru -2 of posix_path
            try
                do Shell script "ln -s " & quoted form of posix_path ¬
                    & " " & quoted form of (posix_path & ".sym")
            on error
                try
                    do Shell script "ln -s " & quoted form of posix_path ¬
                        & " " & quoted form of (posix_path & ".sym") with administrator privileges

                end try
            end try
        end try
    end repeat
end open

Vous pouvez également éditer [application] /Contents/Info.plist pour ajouter

<key>LSUIElement</key>
<true/>

Juste avant le dernier </ dict>. Cela signifierait que l'application fonctionnerait en arrière-plan et ne viendrait pas au premier plan lorsque vous avez cliqué dessus.

0
Benjamin Dobson