首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Automator -处理将从Applescript传递到Shell脚本的路径上的空格

Automator -处理将从Applescript传递到Shell脚本的路径上的空格
EN

Stack Overflow用户
提问于 2019-07-16 02:45:30
回答 2查看 629关注 0票数 0

我有一个AppleScript处理别名表单中的路径,并将它们转换为posix。

这些路径将由此automator工作流的第二步中的shell脚本处理。

问题是路径中包含空格。

我不知道如何处理这个问题,所以我使用此子例程删除任何空格并将其替换为\

代码语言:javascript
复制
on replaceChars(this_text, search_string, replacement_string)
    set saveTID to AppleScript's text item delimiters
    set AppleScript's text item delimiters to the search_string
    set the item_list to every text item of this_text
    set AppleScript's text item delimiters to the replacement_string
    set this_text to the item_list as string
    set AppleScript's text item delimiters to saveTID
    return this_text
end replaceChars

在Applescript部分,我这样做

代码语言:javascript
复制
-- convert the path from the alias form to posix
set fileInputPosix to (the POSIX path of thePath)

-- replace " " with "\ "
set quotedForm to replaceChars(fileInputPosix, space, "\\ ")

在这一点上,路径看起来没有问题,如下所示

代码语言:javascript
复制
'/Users/myUser/Desktop/my\ video\ file.png'

但是,当我将此路径传递给shell脚本时,它不会接受该路径。

EN

回答 2

Stack Overflow用户

发布于 2019-07-16 03:02:53

只需引用shell行中的路径并删除搜索和替换部分

代码语言:javascript
复制
/usr/local/bin/ffmpeg -I "$1" -vf "select=eq(n\,$3)" -vframes 1 "$2"
票数 2
EN

Stack Overflow用户

发布于 2019-07-16 03:09:13

您可以引用整个字符串或使用quoted form of智能地引用字符串,也可以按照您尝试的方式对单个字符进行转义,但在这种情况下,您需要对每个转义字符进行转义,例如:

代码语言:javascript
复制
quoted form of “/Users/myUser/Desktop/my video file.png”
“/Users/myUser/Desktop/my\\ video\\ file.png”
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57045531

复制
相关文章

相似问题

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