我有一个AppleScript处理别名表单中的路径,并将它们转换为posix。
这些路径将由此automator工作流的第二步中的shell脚本处理。
问题是路径中包含空格。
我不知道如何处理这个问题,所以我使用此子例程删除任何空格并将其替换为\
。
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部分,我这样做
-- 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, "\\ ")
在这一点上,路径看起来没有问题,如下所示
'/Users/myUser/Desktop/my\ video\ file.png'
但是,当我将此路径传递给shell脚本时,它不会接受该路径。
发布于 2019-07-16 03:02:53
只需引用shell行中的路径并删除搜索和替换部分
/usr/local/bin/ffmpeg -I "$1" -vf "select=eq(n\,$3)" -vframes 1 "$2"
发布于 2019-07-16 03:09:13
您可以引用整个字符串或使用quoted form of
智能地引用字符串,也可以按照您尝试的方式对单个字符进行转义,但在这种情况下,您需要对每个转义字符进行转义,例如:
quoted form of “/Users/myUser/Desktop/my video file.png”
“/Users/myUser/Desktop/my\\ video\\ file.png”
https://stackoverflow.com/questions/57045531
复制相似问题