替换字符applescript时出错

问题描述 投票:1回答:1

我试图制作一个脚本,以applecript应用程序的形式执行可运行的Jar文件。我对applescript不是很有经验,所以我大部分都没有使用在线代码片段。我遇到的第一个问题是目录自动格式化为使用“:”而不是斜杠(例如“usr:bin”而不是“usr / bin”)所以我发现了一些应该替换的东西: /。但是,每次都会产生错误。

我几乎找不到如何解决我的错误,我发现的东西对这些情况非常具体,对我来说没什么意义。

这是我的代码:

tell application "Finder"
    set current_path to container of (path to me) as alias
end tell

set AppleScript's text item delimiters to ":"
set currPath to text items of current_path
set AppleScript's text item delimiters to "/"
set current_path to currPath as string
set AppleScript's text item delimiters to {""}
currPath

tell application "Terminal"
    activate
    set currentTab to do script ("cd " & current_path)
    set currentTab to do script ("java -jar Inoisulcnoc Pre-Alpha 2")
end tell

我每次得到的错误都说:

错误“无法获取别名的每个文本项目”Macintosh HD:用户:knotsnappy:桌面:Inoisulcnoc Pre-Alpha 2:\“。”从别名“Macintosh HD:用户:knotsnappy:桌面:Inoisulcnoc Pre-Alpha 2:”的每个文本项编号-1728

我应该如何解决这个问题?

macos terminal applescript sh executable-jar
1个回答
1
投票

您需要将标准路径更改为POSIX路径。

tell application "Finder"
    set current_path to (POSIX path of (container of (path to me) as alias))
end tell

tell application "Terminal"
    activate
    set currentTab to do script ("cd " & current_path)
    set currentTab to do script ("java -jar Inoisulcnoc Pre-Alpha 2")
end tell

一旦拥有正确的语法,就不需要分隔符等。

© www.soinside.com 2019 - 2024. All rights reserved.