2012-01-11 49 views
1

我使用馬赫桌面呼應腳本的結果爲Desklet,所以它必須是這種格式:轉換AppleScript的一個行

回聲「告訴應用程序‘iTunes的’返回當前曲目的專輯」 | osascript

我有一個單行輸入數據,所以腳本需要是一個長字符串。 這可能是整個事情必須包含在一個單引號後面的回聲,如下所示:

echo'[entire script]'| osascript

如何將下面的AppleScript轉換爲一行?

set some_file to "Macintosh HD:Users:Zade:Library:Application Support:Notational Data:Words.txt" as alias 
set the_text to read some_file as string 
set the text item delimiters of AppleScript to ", " 
set the_lines to (every text item of the_text) 
return some item of the_lines 

這裏是我嘗試:

echo 'set some_file to "Macintosh HD:Users:Zade:Library:Application Support:Notational Data:Words.txt" as alias -e set the_text to read some_file as string -e set the text item delimiters of AppleScript to ", " -e set the_lines to (every text item of the_text) -e return some item of the_lines' | osascript 

而且它給出了這個錯誤:

107:112:語法錯誤: 「設置」 不能識別號後去。 (-2740)

+0

不幸的是,我不知道從哪裏開始,特別是因爲它全部在一條線上。我認爲這對你們來說會很簡單。 – Zade 2012-01-11 20:38:48

+0

@Zade你是對的,這很容易,但你只是把它變得比它需要的更復雜。查看我的編輯瞭解更多信息。 :) – fireshadow52 2012-01-12 00:59:07

+0

@Zade我的意思是包含每個**個人**行,而不是整個事情。另外,哪個'set'做錯誤點?我沒有使用Mach Desktop,但根據我對使用'osascript'的瞭解,這些行由'-e'分隔,並且包含在單引號中。 – fireshadow52 2012-01-12 03:28:46

回答

1

我想你可以試試這個腳本。不過,我對你實際上想要完成的事情感到困惑,所以如果這個腳本不能令人滿意,我很抱歉。

echo 'set some_file to "~/Library/Application Support/Notational Data/Words.txt" as POSIX file as alias' -e 'set the_text to read some_file' -e 'set the text item delimeters of AppleScript to ","' -e 'set the lines to (every text item of the_text)' -e 'return the lines' | osascript 

編輯: @Zade那將是因爲Words.txt不存在。別名只涉及現有的文件。因此,您必須選擇一個存在的文件。這裏有一個簡單的方法才能看到正確的語法是什麼文件引用:

set some_file to (choose file) 

你會發現,文件路徑是用冒號分隔(:),而不是斜槓。話雖如此,選擇一個存在的文件,然後用該文件運行腳本。

+0

謝謝。查看我的更新說明。我試圖儘可能清楚,所以請告訴我是否還有什麼困惑。你寫的這行給了我下面的錯誤:99:104:語法錯誤:一個「set」不能跟在這個標識符之後。 (-2740) – Zade 2012-01-11 20:34:16

+0

@Zade是否說哪個「set」導致錯誤?另外,請嘗試從AppleScript編輯器運行腳本。用換行符替換所有-e,並取出所有單引號。然後,嘗試運行它 – fireshadow52 2012-01-11 22:17:02

+0

在AppleScript中,它表示「無法將文件Words.txt設置爲類型別名。」如果我拿出「作爲別名」,它說「不能將文件寫入類型文件」。同樣的錯誤,如果我也拿出「作爲POSIX文件」。查看現在添加到問題的腳本。 – Zade 2012-01-11 22:36:43