可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
set theFile to path to replay_folder & "ls.txt"
I simply want this path to be the path of replay_folder
and ls.txt
In the shell script line I want the same thing.
do shell script "cd " & replay_folder & " /usr/local/bin/ffmpeg -f concat -i ls.txt -c copy merged.mov"
I get this path with the shell script Macintosh HD:Users:BjornFroberg:Documents:wirecast:Replay-2017-03-17-12_11-1489749062:
But I want this /Users/BjornFroberg/Documents/wirecast/Replay-2017-03-17-12_11-1489749062/
The full code is:
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"
Any help is appreciated :)
回答1:
path to
is part of Standard Scripting Additions and works only with predefined folders. It does not work with custom paths. For example "Macintosh HD:Users:bjornfroberg:documents:"
can be replaced with the relative path
set documentsFolder to path to documents folder as text
which points always to the documents folder of the current user.
replay_folder
HFS path you need to coerce the Finder specifier to text
set theFile to (replay_folder as text) & "ls.txt"
However to pass the replay_folder
to the shell you have to use a POSIX path (slash separated). Since a Finder specifier cannot be coerced directly to POSIX path
you need also first create a HFS path
. Additionally you have to take care that space characters are escaped in the path. Any unescaped space character will break the shell script
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"
回答2:
You can convert an AppleScript path to a Posix path like this:
set applescriptPath to "Macintosh HD:Users:bjornfroberg:documents:wirecast:" set posixPath to (the POSIX path of applescriptPath) log posixPath
Returns /Users/bjornfroberg/documents/wirecast/
Note: Your post's title and your actual question are kind of different topics. Your goal is to turn an AppleScript path (Macintosh HD:Users:bjornfroberg:documents:wirecast
) into a posix path (/Users/bjornfroberg/documents/wirecast/
), to which you want to append a file name; you can use the code above in conjunction with your existing code to build the full path:
set theFile to POSIX path of (replay_folder as text) & "ls.txt"
Depending what you're trying to do, once you have defined your path, you may need to convert it to a posix file to manipulate it via AppleScript. For example, if you want to open it via AppleScript:
set pFile to POSIX file theFile tell application "Finder" to open pFile
(See POSIX path in applescript from list not opening. Raw path works)