小小白,在弄一個 AppleScript 使用 root 身份執行一個 shell script 遇到了以下問題
文件結構如下:
/Users/apple/myscript/
myApplescript.app
bash.sh
Config.plist
其中 Config.plist 要複製到 /private/var/db/dslocal/nodes/Default/computergroups
我想把 bash.sh 與 Config.plist 文件放到 myApplescript.app/Contents/Resources/Scripts 裡面(即是把 Applescript 保存爲 app 格式后再把另外 2 個文件放到 app 裡面進行調用)
而 myApplescript.app 的路徑不確定,可能被放在不同文件夾,怎麼獲取 App 其當前路徑?
do shell script “ sh 怎麼自動得到 App 當前路徑?/Contents/Resources/Scripts/bash.sh ” user name "root" password "rootpassword" with administrator privileges
set TargetPath to “ /private/var/db/dslocal/nodes/Default/computergroups ”
do shell script “ cp – r 怎麼自動得到 App 當前路徑?/Contents/Resources/Scripts/Config.plist ” & TargetPath user name "root" password "rootpassword" with administrator privileges
AppleScript 該怎麼改?大神幫忙看看,謝謝
1
wolf1981 OP anyone can help?
|
2
johnnyb 2015-09-25 14:46:49 +08:00
通过
```applescript set scptPath to POSIX path of ((path to me) as Unicode text) ``` 可获得当前 .applescript 的路径。如果你把 .applescript 编译成 .app 放在 `/path/to/YourBundle.app` 那么前面语句得到的是 `/path/to/YourBundle.app/Contents/Resources/Scripts/main.scpt` |
3
wolf1981 OP |
4
johnnyb 2015-09-25 18:09:54 +08:00
set dirPath to do shell script "echo $(dirname " & quoted form of POSIX path of scptPath & ")"
|