2017-03-17 77 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

你說得對。我改變了帖子的標題。 –

相關問題