2011-08-16 28 views
9

我試圖從命令行或從Python程序創建Finder別名。我已經在網上搜索[1] [2] [3],發現的AppleScript此位:如何從命令行創建Macintosh Finder別名?

$ osascript -e 'tell application "Finder" to make new alias at POSIX file "/Users/vy32/cyber.txt" to POSIX file "/Users/vy32/a/deeper/directory/cyber.txt"' 

不幸的是,它給了我這個錯誤:

29:133: execution error: Finder got an error: AppleEvent handler failed. (-10000) 

[1] http://hayne.net/MacDev/Bash/make_alias

[2] https://discussions.apple.com/thread/1041148?start=0&tstart=0

[3] http://hintsforums.macworld.com/showthread.php?t=27642

我做錯了什麼?

+0

出於興趣,是 「啓用輔助設備的訪問」 打開了嗎? http://hints.macworld.com/article.php?story=20060203225241914 – Coxy

+0

我認爲你把'at'和'to'轉換爲attribtutes。 – fireshadow52

回答

7

關於您的消息,請嘗試查看Console.app。可能是源文件不存在。當我嘗試使Xcode 4.3+應用程序可見時,這可以幫助我。我發現工作代碼:

$ osascript -e 'tell application "Finder" to make alias file to POSIX file "/file/to/make/link/from" at POSIX file "/folder/where/to/make/link"' 

例如:

$ osascript -e 'tell application "Finder" to make alias file to POSIX file "/Applications/Xcode.app/Contents/Applications/OpenGL ES Performance Detective.app" at POSIX file "/Users/mylogin/Applications"' 
+0

工作正常!謝謝。 – vy32

+0

@Leandros指出了一個錯誤,他的解決方案實際上可行...... –

+0

@MarkSetchell你能告訴你更多關於你的環境嗎? –

0

在AppleScript的工作命令:

tell application "Finder" 
    make new alias at POSIX file "/Path/to/location" to POSIX file "/Path/to/file.ext" 
end tell 

加入鹽調味。

+0

@Phillip Regan不需要實際的別名引用嗎? – fireshadow52

+0

@ fireshadow52:沒有。我抓住了一個隨機文件的路徑,並使用我的家庭文件夾(我只存儲操作系統的默認設置),它只是工作(沒有雙關語意圖);一個別名出現在我指定的位置。 –

+0

我真的希望能夠從命令行執行此操作,但是當我拿到代碼並將其更改爲'osascript -e'將應用程序「Finder」更改爲'後跟第二行時,它不起作用...? – vy32

1

這種方法在命令行工作:

osascript -e 'tell application "Finder" to make alias file to alias "imac:Users:vy32:current:cyber.txt" at "imac:Users:vy32:foobar"' 

foobar是我的主目錄的目錄。

+0

其他例子對我來說不起作用,但是這個用舊式「Mac OS」文件路徑。謝謝。 – 2014-04-16 17:28:05

3

爲大家的AppleEvent handler failed錯誤掙扎:

make alias並不像ln -s工作,你不必指定目的地文件,您必須指定目的地目錄,別名的文件名是源文件/文件夾。

例子:

tell application "Finder" to make alias file to (POSIX file "/Applications/Mail.app") at (POSIX file "/Users/leandros/Desktop")