use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSURL : a reference to refMe's NSURL
property refNSMutableString : a reference to refMe's NSMutableString
property refNSMutableArray : a reference to refMe's NSMutableArray
property refNSArray : a reference to refMe's NSArray
property refAVURLAsset : a reference to refMe's AVURLAsset
property refAVMediaTypeVideo : a reference to refMe's AVMediaTypeVideo
property listUTI : {"com.apple.quicktime-movie", "public.mpeg-4", "public.mpeg-2-transport-stream"}
on run
doLogView()
set objFileManager to refMe's NSFileManager's alloc()'s init()
log className() of objFileManager as text
set ocidUserDownloadsPath to (objFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask))
log ocidUserDownloadsPath as list
log className() of ocidUserDownloadsPath as text
set ocidUserDownloadsPath to ocidUserDownloadsPath's objectAtIndex:0
log ocidUserDownloadsPath as text
log className() of ocidUserDownloadsPath as text
set aliasDefaultLocation to ocidUserDownloadsPath as alias
log aliasDefaultLocation as alias
log class of aliasDefaultLocation
set listChooseFileAliasList to (choose file with prompt "ムービーファイルを選んでください" default location aliasDefaultLocation of type listUTI with invisibles and multiple selections allowed without showing package contents) as list
open listChooseFileAliasList
objFileManager's release()
end run
on open listChooseFileAliasList
set objFileManager to refMe's NSFileManager's alloc()'s init()
log className() of objFileManager as text
repeat with objFile in listChooseFileAliasList
set aliasFilePath to objFile as alias
set strFilePath to POSIX path of objFile
set ocidFilePath to (refNSString's stringWithString:strFilePath)
log ocidFilePath as text
log className() of ocidFilePath as text
if strFilePath contains "~" then
set ocidPosixPath to refNSString's stringByExpandingTildeInPath()
log ocidPosixPath as text
log className() of ocidPosixPath as text
end if
set ocidURLPath to (refNSURL's fileURLWithPath:ocidFilePath)
log ocidURLPath as text
log ocidURLPath's className() as text
set ocidURLContainerDirPath to ocidURLPath's URLByDeletingLastPathComponent()
log ocidURLContainerDirPath as text
log className() of ocidURLContainerDirPath as text
set strURLContainerDirPath to ocidURLContainerDirPath's relativePath()
log strURLContainerDirPath as text
log className() of strURLContainerDirPath as text
set ocidFileName to ocidURLPath's lastPathComponent()
log ocidFileName as text
log className() of ocidFileName as text
set ocidPathExtension to ocidURLPath's pathExtension()
log ocidPathExtension as text
log className() of ocidPathExtension as text
set ocidMutableArray to (refNSMutableArray's alloc()'s initWithCapacity:0)
log ocidMutableArray as list
log className() of ocidMutableArray as text
set ocidNSCFCharacterSet to (refMe's NSCharacterSet's characterSetWithCharactersInString:".")
log className() of ocidNSCFCharacterSet as text
set ocidMutableArray to (ocidFileName's componentsSeparatedByCharactersInSet:ocidNSCFCharacterSet)
log ocidMutableArray as list
log className() of ocidMutableArray as text
set ocidShortFileName to (ocidMutableArray's objectAtIndex:0)
log ocidShortFileName as text
log className() of ocidShortFileName as text
log "###Input"
log "Alias: " & aliasFilePath as text
log "POSIX: " & strFilePath as text
log "alias Container" & ocidURLContainerDirPath as text
log "POSIX Container" & strURLContainerDirPath as text
log "FileName: " & ocidFileName as text
log "Extension: " & ocidPathExtension as text
log "ShortFileName: " & ocidShortFileName as text
set ocidAVURLAsset to (refAVURLAsset's alloc()'s initWithURL:ocidURLPath options:(missing value))
log className() of ocidAVURLAsset as text
set ocidVideoAssetTrack to (ocidAVURLAsset's tracksWithMediaType:(refAVMediaTypeVideo))
log className() of ocidVideoAssetTrack as text
set ocidAsset to (ocidVideoAssetTrack's objectAtIndex:0)
log ocidAsset as list
log className() of ocidAsset as text
set ocidBounds to ocidAsset's naturalSize()
log ocidBounds as record
log class of ocidBounds as text
set numDimensionsW to width of ocidBounds as integer
set numDimensionsH to height of ocidBounds as integer
set strDimensionsW to numDimensionsW as text
set strDimensionsH to numDimensionsH as text
set ocidFrameRate to ocidAsset's nominalFrameRate()
log ocidFrameRate as real
log class of ocidFrameRate as text
set strFPS to ocidFrameRate as text
if strFPS contains "." then
set ocidDecimalNumber to (refMe's NSDecimalNumber's decimalNumberWithString:strFPS)
log ocidDecimalNumber as text
log className() of ocidDecimalNumber as text
set ocidNSNumberFormatter to refMe's NSNumberFormatter's alloc()'s init()
log ocidNSNumberFormatter
log className() of ocidNSNumberFormatter as text
(ocidNSNumberFormatter's setPositiveFormat:"##0.00")
set ocidDecimalNumber to (ocidNSNumberFormatter's stringFromNumber:ocidDecimalNumber)
log ocidDecimalNumber as text
log className() of ocidDecimalNumber as text
set strFPS to ocidDecimalNumber as text
ocidNSNumberFormatter's release()
end if
log "###VideoInfo"
log "W: " & strDimensionsW
log "H: " & strDimensionsH
log "FPS: " & strFPS
set strNewFileName to ((ocidShortFileName as text) & "." & strDimensionsW & "x" & strDimensionsH & "." & strFPS & "fps.mov") as text
set strNewFilePath to ((strURLContainerDirPath as text) & "/" & strNewFileName) as text
log "###OutPut"
log "AliasOutPutDir: " & ocidURLContainerDirPath
log "NewFileName: " & strNewFileName
log "NewFilePath: " & strNewFilePath
set ocidDistFilePath to (refNSString's stringWithString:strNewFilePath)
set boolFileExists to (objFileManager's fileExistsAtPath:ocidDistFilePath isDirectory:false)
log boolFileExists
if boolFileExists is true then
set strNewFileName to (strShortFileName & "." & strDimensionsW & "x" & strDimensionsH & "." & strFPS & "fps.1.mov") as text
set strNewFilePath to (strContainerDirPath & strNewFileName) as text
set ocidDistFilePath to (refNSString's stringWithString:strNewFilePath)
end if
tell application "QuickTime Player"
set objOpenDoc to open file aliasFilePath
tell objOpenDoc
export objOpenDoc in (POSIX file strNewFilePath) using settings preset "4K"
end tell
close objOpenDoc
end tell
ocidAVURLAsset's release()
ocidVideoAssetTrack's release()
objFileManager's release()
end repeat
objFileManager's release()
end open
on doLogView()
tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
tell application "Script Editor"
tell application "System Events"
tell process "Script Editor"
tell window 1
tell splitter group 1
tell splitter group 1
tell group 1
tell checkbox "返された値"
set boolValue to value as boolean
end tell
if boolValue is false then
click checkbox "返された値"
end if
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end if
end repeat
end doLogView