Это работает нормально, если только в пути к папке нет пробелов (и, возможно, других специальных символов). если есть пробелы, то проверка на наличие папки не проходит, как я могу заставить ее работать?
tell application "Finder"
set mySaveASDelimiters to AppleScript's text item delimiters
set myScriptFilePath to (path to me)
set mySourceFolder to folder of myScriptFilePath
set myFileAliasList to the entire contents of mySourceFolder
set myPOSIXSourceFolder to URL of mySourceFolder
set myPOSIXSourceFolder to characters 8 thru -1 of myPOSIXSourceFolder as string
repeat with myFile in myFileAliasList
set myFileName to name of myFile
log "myFileName: " & myFileName
if (myFileName ends with ".txt") then
set AppleScript's text item delimiters to "."
set myFolderName to first text item of myFileName
set AppleScript's text item delimiters to mySaveASDelimiters
set myFolderPath to myPOSIXSourceFolder & myFolderName as string
log "myFolderPath: " & myFolderPath
tell application "System Events"
if not (exists folder myFolderPath) then
beep
display dialog "Could not find Folder for File: " & myFileName
return {}
end if
end tell
end if
end repeat
end tell
Позволяет сделать это проще:
set myScriptFilePath to (path to me)
set mySourceFolder to folder of myScriptFilePath
set myPOSIXSourceFolder to POSIX path of mySourceFolder
Я получаю ошибку на myPOSIXSourceFolder, почему! Я просто хочу текущий путь к папке в нотации POSIX! Я исправил это сейчас:
set myAppFile to (path to me)
set myAppFilePath to ((path to me as text) & "::") --Magic I was looking for
set myAppFolder to POSIX path of (myAppFilePath) as string
set myFilePath to myAppFolder & "ModTest1"
log "myAppFilePath: " & myAppFilePath
log "myAppFile: " & myAppFile
log "myAppFolder: " & myAppFolder
log "myFilePath: " & myFilePath
set thePath to myFilePath
tell application "System Events"
if exists folder thePath then
beep
end if
end tell