2017-03-17 169 views
0

我试图创建一个文本文件,我的ffmpeg命令可以用来合并两个视频文件。我遇到的问题是让我的文件夹/文件路径看起来像我想要的。这两条线引起我的问​​题是:如何将AppleScript路径转换为posix路径并传递给shell脚本?

set theFile to path to replay_folder & "ls.txt"

我只想把这个路径的replay_folderls.txt

路径在shell脚本行我希望同样的事情。

do shell script "cd " & replay_folder & " /usr/local/bin/ffmpeg -f concat -i ls.txt -c copy merged.mov"

我得到的shell脚本Macintosh HD:Users:BjornFroberg:Documents:wirecast:Replay-2017-03-17-12_11-1489749062:

这条道路,但我想这/Users/BjornFroberg/Documents/wirecast/Replay-2017-03-17-12_11-1489749062/

完整的代码是:

tell application "Finder" 
set sorted_list to sort folders of folder ("Macintosh HD:Users:bjornfroberg:documents:wirecast:") by creation date 
set replay_folder to item -1 of sorted_list 
set replay_files to sort items of replay_folder by creation date 
end tell 

set nr4 to "file '" & name of item -4 of replay_files & "'" 
set nr3 to "file '" & name of item -3 of replay_files & "'" 

set theText to nr4 & return & nr3 

set overwriteExistingContent to true 

set theFile to path to replay_folder & "ls.txt" --actual path is: POSIX file "/Users/BjornFroberg/Documents/wirecast/Replay-2017-03-17-12_11-1489749062/ls.txt" 

set theOpenedFile to open for access file theFile with write permission 

if overwriteExistingContent is true then set eof of theOpenedFile to 0 

write theText to theOpenedFile starting at eof 

close access theOpenedFile 

do shell script "cd " & replay_folder & " 
/usr/local/bin/ffmpeg -f concat -i ls.txt -c copy merged.mov" 

任何帮助表示赞赏:)

回答

1

path to是标准脚本附加的一部分,并且只与预定义文件夹的作品。它不适用于自定义路径。例如"Macintosh HD:Users:bjornfroberg:documents:"可以用相对路径替换

set documentsFolder to path to documents folder as text 

它总是指向当前用户的文档文件夹。


replay_folder是一个搜索对象指定符可以 - 在此特定形式 - 仅是搜索处理。要创建一个(冒号分隔)HFS路径,你需要强迫 Finder中说明符的文本

set theFile to (replay_folder as text) & "ls.txt" 

但是到replay_folder传给你必须使用一个POSIX路径壳(斜杠分隔)。由于Finder说明符不能直接输入POSIX path,因此您还需要首先创建一个HFS path。另外,您必须注意空间字符在路径中转义。任何非转义的空格字符将打破shell脚本

set replay_folderPOSIX to POSIX path of (replay_folder as text) 
do shell script "cd " & quoted form of replay_folderPOSIX & " 
/usr/local/bin/ffmpeg -f concat -i ls.txt -c copy merged.mov" 
+0

这工作完美。谢谢! HFS代表什么? –

+0

[分层文件系统](https://en.wikipedia.org/wiki/Hierarchical_File_System) – vadian

1

你可以一个AppleScript路径转换为Posix的路径是这样的:

set applescriptPath to "Macintosh HD:Users:bjornfroberg:documents:wirecast:" 

set posixPath to (the POSIX path of applescriptPath) 

log posixPath 

返回/Users/bjornfroberg/documents/wirecast/

注:您的文章的标题和你的实际问题,是一种不同的主题。您的目标是将AppleScript路径(Macintosh HD:Users:bjornfroberg:documents:wirecast)转换为posix路径(/Users/bjornfroberg/documents/wirecast/),您希望将其附加到文件名;您可以结合使用上面的代码与您现有的代码来构建完整路径:

set theFile to POSIX path of (replay_folder as text) & "ls.txt" 

,取决于您所试图做的,一旦你已经确定你的路径是什么,你可能需要将其转换为POSIX 文件通过AppleScript操纵它。例如,如果你想通过AppleScript的打开它:

set pFile to POSIX file theFile 

tell application "Finder" to open pFile 

(见POSIX path in applescript from list not opening. Raw path works

+0

你说得对。我改变了帖子的标题。 –