替换字符 applescript 时出错
Error when replacing characters applescript
我正在尝试制作一个脚本,以 applescript 应用程序的形式执行可运行的 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
我每次得到的错误都是:
错误 "Can’t get every text item of alias \"Macintosh HD:Users:knotsnappy:Desktop:Inoisulcnoc Pre-Alpha 2:\"."编号 -1728 来自 每个 文本项 of alias "Macintosh HD:Users:knotsnappy:Desktop:Inoisulcnoc Pre-Alpha 2:"
我该如何解决这个问题?
您需要将标准路径更改为 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
一旦语法正确,就不需要分隔符等了。
我正在尝试制作一个脚本,以 applescript 应用程序的形式执行可运行的 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
我每次得到的错误都是:
错误 "Can’t get every text item of alias \"Macintosh HD:Users:knotsnappy:Desktop:Inoisulcnoc Pre-Alpha 2:\"."编号 -1728 来自 每个 文本项 of alias "Macintosh HD:Users:knotsnappy:Desktop:Inoisulcnoc Pre-Alpha 2:"
我该如何解决这个问题?
您需要将标准路径更改为 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
一旦语法正确,就不需要分隔符等了。