我正在尝试编写一个脚本,以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
我每次得到的错误是这样的:
错误“无法获取别名\"Macintosh HD:Users:knotsnappy:Desktop:Inoisulcnoc -Alpha 2:\”的每个文本项。“number -1728来自的别名"Macintosh HD:Users:knotsnappy:Desktop:Inoisulcnoc Pre-Alpha2:“的每个文本项目:
我该如何解决这个问题呢?
发布于 2019-04-08 08:17:58
您需要将标准路径更改为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
一旦有了正确的语法,分隔符等就不再需要了。
https://stackoverflow.com/questions/55564399
复制相似问题