作者ballII (ballII)
站內MAC
標題[軟體] 如何做一個terminal script?
時間Wed Aug 31 01:15:30 2011
末代Powerbook 12"
10.4.11
我知道如何在terminal裡跑一個指令
(例如在 > 之後打 sudo pmset -a hibernatemode 1 ,然後按 return),
但我現在希望製作一個檔案,雙擊就可跑完該指令。
我以為用textedit編輯:
#!/bin/sh
sudo pmset -a hibernatemode 0
然後存成 .sh 還是 .command ,就大功告成了,
但是雙擊後只會叫出 terminal,並不會跑指令。
請問正確作法應該是什麼呢?謝謝。
註:
我的老 Powerbook 12" 已經破解過,可以成功hibernate,
(破解方式
http://matt.ucc.asn.au/apple/machibernate.html )
所以 sudo pmset -a hibernatemode 1 指令是有效的。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 1.161.210.213
1F:推 xwan227770:你應該是要用terminal進去那個檔案的目錄 08/31 01:52
2F:→ xwan227770:然後打入類似 sh (檔案名) 或是 ./(檔案名) 去執行吧 08/31 01:53
3F:→ ballII:我希望雙擊就可執行 08/31 01:56
4F:推 seedman:我會用automator開新應用程式 工具程式->執行shell 08/31 03:47
5F:推 iPluto:樓上正解 08/31 03:55
6F:推 theory:因為你的 sh 檔沒有"執行"權限,要用 chmod +x 該檔後才行 08/31 23:33
7F:→ cendre:可以打開AppleScript Editor,輸入底下一行: 09/01 10:55
8F:→ cendre:do shell script "sudo pmset -a hibernatemode 0" 09/01 10:55
9F:→ cendre:儲存,對話框中File Format的部份選擇Application 09/01 10:56
10F:→ cendre:會得到一個點兩下執行該指令的.app檔 09/01 10:57
11F:→ ballII:謝謝各位 09/01 11:41