2012-12-05 114 views
2

我有一個應用程序和一個.sh文件。我需要一個蘋果腳本,當雙擊時,設置.sh文件的權限並運行它。 下面是我的代碼:設置當前目錄 - 蘋果腳本

set app_directory to POSIX path of ((container of (path to me)) as text) 

tell application "Terminal" to do shell script "chmod 777 " & app_directory & " start.sh" 
tell application "Terminal" to do shell script app_direcory & "start.sh" 

,但我得到以下錯誤:

error "Can’t make container of alias \"Macintosh HD:Users:santhosh:Desktop:EPPFN ver1:Barcode Application_mac:test_app.app:\" into type text." number -1700 from container of alias "Macintosh HD:Users:santhosh:Desktop:EPPFN ver1:Barcode Application_mac:test_app.app:" to text

如何設置當前路徑,然後使用相對路徑來運行該腳本。

編輯: 我修改了代碼:

set x to POSIX file ((POSIX path of (path to me)) & "/..") as text 
set thescript to ("chmod 777 " & x & "start.sh") as text 
tell application "Terminal" to do shell script (thescript) 

仍然沒有運氣。

回答

0

嘗試:

tell application "System Events" to set app_directory to POSIX path of (container of (path to me)) 
set thescript to ("chmod 777 " & quoted form of (app_directory & "/start.sh")) 
do shell script thescript