2012-12-05 85 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