| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- |
| 004 | (* |
| 005 |
|
| 006 | mdls を使う場合 |
| 007 | TS=MPEG1ビデオ等で値が取れないのでmp4専用と思った方がいい |
| 008 |
|
| 009 |
|
| 010 |
|
| 011 | com.cocolog-nifty.quicktimer.icefloe *) |
| 012 | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- |
| 013 | use AppleScript version "2.8" |
| 014 | use framework "Foundation" |
| 015 | use scripting additions |
| 016 | property refMe : a reference to current application |
| 017 |
|
| 018 |
|
| 019 |
|
| 020 | ############################# |
| 021 | ###入力ファイル |
| 022 | ############################# |
| 023 | tell current application |
| 024 | set strName to name as text |
| 025 | end tell |
| 026 | if strName is "osascript" then |
| 027 | tell application "Finder" to activate |
| 028 | else |
| 029 | tell current application to activate |
| 030 | end if |
| 031 | #デスクトップ |
| 032 | set aliasDesktopDirPath to (path to desktop from user domain) as alias |
| 033 | set listUTI to {"public.movie"} as list |
| 034 | set strTitle to ("ファイル選択") as text |
| 035 | set strPrompt to ("ムービーファイルを選んでください") as text |
| 036 | tell application "SystemUIServer" |
| 037 | activate |
| 038 | set listAliasFilePath to (choose file with prompt (strPrompt) default location (aliasDesktopDirPath) of type (listUTI) with invisibles, showing package contents and multiple selections allowed) as list |
| 039 | end tell |
| 040 |
|
| 041 | #ソート 名前順 |
| 042 | tell application "Finder" |
| 043 | set listSortedFilePath to (sort of listAliasFilePath by name) as alias list |
| 044 | end tell |
| 045 |
|
| 046 | #エイリアスリストの中のパスの数 |
| 047 | set numCntList to (count of listSortedFilePath) as integer |
| 048 |
|
| 049 | set aliasTempDir to (path to temporary items from user domain) as alias |
| 050 | set strTempDir to (POSIX path of aliasTempDir) as text |
| 051 |
|
| 052 | repeat with itemIntNo from 1 to numCntList by 1 |
| 053 | #開くムービーのエイリアス・パスをエイリアスリストから取得して |
| 054 | set aliasItemFilePath to (item itemIntNo of listSortedFilePath) as alias |
| 055 | #ファイル名 |
| 056 | set strFileName to (name of (info for aliasItemFilePath)) as text |
| 057 | set strPlistFileName to ("" & strFileName & ".plist") as text |
| 058 | set strPlistFilePath to ("" & strTempDir & strPlistFileName & "") as text |
| 059 | |
| 060 | #UNIXPATH |
| 061 | set strItemFilePath to (POSIX path of aliasItemFilePath) as text |
| 062 | set strItemFilePathESC to doPathEscape(strItemFilePath) as text |
| 063 | set strPlistFilePathESC to doPathEscape(strPlistFilePath) as text |
| 064 | #コマンド整形 |
| 065 | set strCmd to ("/usr/bin/mdls -plist - \"" & strItemFilePathESC & "\" > \"" & strPlistFilePathESC & "\"") as text |
| 066 | set strStdOut to (do shell script strCmd) as text |
| 067 | |
| 068 | |
| 069 | #コマンド作成されたPLISTを開いて値を取得する |
| 070 | tell application "System Events" |
| 071 | tell property list file strPlistFilePath |
| 072 | set numWpx to (value of property list item "kMDItemPixelWidth") as integer |
| 073 | set numHpx to (value of property list item "kMDItemPixelHeight") as integer |
| 074 | set numBitRate to (value of property list item "kMDItemVideoBitRate") as integer |
| 075 | set numFileSize to (value of property list item "kMDItemFSSize") as number |
| 076 | end tell |
| 077 | end tell |
| 078 | |
| 079 | log numWpx |
| 080 | log numHpx |
| 081 | end repeat |
| 082 |
|
| 083 |
|
| 084 | return |
| 085 |
|
| 086 |
|
| 087 | ######################## |
| 088 | #パスのエスケープ |
| 089 | to doPathEscape(strFilePath) |
| 090 | set strFilePath to strFilePath as text |
| 091 | set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath) |
| 092 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
| 093 | set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath) isDirectory:(false) |
| 094 | set listEscChar to {"\\", "\"", "$", "`"} as list |
| 095 | repeat with itemEscChar in listEscChar |
| 096 | set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:(itemEscChar) withString:("\\" & itemEscChar & "")) |
| 097 | end repeat |
| 098 | set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:("!") withString:("\"'!'\"")) |
| 099 | |
| 100 | return ocidFilePath |
| 101 | end doPathEscape |