【问题标题】:Set current directory - apple script设置当前目录 - 苹果脚本
【发布时间】:2012-12-05 11:54:09
【问题描述】:

我有一个应用程序和一个.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"

但我收到以下错误:

错误“无法将别名容器 \"Macintosh HD:Users:santhosh:Desktop:EPPFN ver1:Barcode Application_mac:test_app.app:\" 转换为文本。”从别名“Macintosh HD:Users:santhosh:Desktop:EPPFN ver1:Barcode Application_mac:test_app.app:”的容器编号 -1700 到文本

如何设置当前路径,然后使用相对路径运行脚本。

编辑: 我将代码修改为:

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)

还是没有运气。

【问题讨论】:

    标签: macos applescript


    【解决方案1】:

    试试:

    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
    

    【讨论】:

      猜你喜欢
      • 2012-04-11
      • 1970-01-01
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 2011-07-12
      相关资源
      最近更新 更多