首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >替换字符applescript时出错

替换字符applescript时出错
EN

Stack Overflow用户
提问于 2019-04-08 06:56:22
回答 1查看 133关注 0票数 1

我正在尝试编写一个脚本,以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:“的每个文本项目:

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55564399

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档