AppleScript AVAsset

サウンドファイルのリネーム(データレート、サンプルレート、時間分入り)


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AVFoundation"
use framework "CoreMedia"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()

###################################
#####入力フォルダ
###################################
###ダイアログのデフォルト
set ocidUserDesktopPath to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set aliasDefaultLocation to ocidUserDesktopPath as alias
tell application "Finder"
  ## set aliasDefaultLocation to container of (path to me) as alias
end tell
###ダイアログテキスト
set strPromptText to "入力フォルダを選んでください"
try
  set listResponse to (choose folder strPromptText with prompt strPromptText default location aliasDefaultLocation without multiple selections allowed, invisibles and showing package contents) as list
on error
log "エラーしました"
return
end try
###エリアス
set aliasDirPath to (item 1 of listResponse) as alias
###UNIXパス
set strDirPath to POSIX path of aliasDirPath as text
###String
set ocidDirPath to refMe's NSString's stringWithString:strDirPath
###NSURL
set ocidDirPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidDirPath isDirectory:true
###########################
###ディレクトリ内のファイルをURLリストに(下位まで)
###########################
set listSubPathArray to appFileManager's subpathsOfDirectoryAtPath:ocidDirPathURL |error|:(reference)
set ocidSubPathArray to item 1 of listSubPathArray

###########################
###本処理
###########################
##ファイルリストの数だけ繰り返し
repeat with itemSubPathArray in ocidSubPathArray
  ####選択したフォルダURLに取得したリストを追加してURLに
  set ocidFilePathURL to (ocidDirPathURL's URLByAppendingPathComponent:itemSubPathArray)
  ####ファイル名取得
  set ocidFileName to ocidFilePathURL's lastPathComponent
  set strFileName to ocidFileName as text
  ####拡張子を取ったベースファイル名
  set ocidBaseFileName to ocidFileName's stringByDeletingPathExtension
  set strBaseFileName to ocidBaseFileName as text
  ####拡張子取得
  set ocidFileExtension to ocidFilePathURL's pathExtension
  set strFileExtension to ocidFileExtension as text
  
  if strFileExtension is "mp3" then
    ####URLのファイル名を取ってコンテナディレクトリに
    set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent
    #####サブを実行
    set listRate to doGetDataAndSampleRate(ocidFilePathURL)
    ###置き換えファイル名の定義
    set strAddFileName to ("." & (item 1 of listRate) & "x" & (item 2 of listRate) & "." & (item 3 of listRate) & "M.") as text
    ####新しいファイル名
    set strNewFileName to strBaseFileName & strAddFileName & strFileExtension as text
    ####コンテナディレクトリに新しいファイル名でリネーム用のURL
    set ocidNewFilePathURL to (ocidContainerDirPathURL's URLByAppendingPathComponent:strNewFileName)
    ####リネームする
    set listResult to (appFileManager's moveItemAtURL:ocidFilePathURL toURL:ocidNewFilePathURL |error|:(reference))
    
  else if strFileExtension is "m4a" then
    ####URLのファイル名を取ってコンテナディレクトリに
    set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent
    #####サブを実行
    set listRate to doGetDataAndSampleRate(ocidFilePathURL)
    ###置き換えファイル名の定義
    set strAddFileName to ("." & (item 1 of listRate) & "x" & (item 2 of listRate) & "." & (item 3 of listRate) & "M.") as text
    ####新しいファイル名
    set strNewFileName to strBaseFileName & strAddFileName & strFileExtension as text
    ####コンテナディレクトリに新しいファイル名でリネーム用のURL
    set ocidNewFilePathURL to (ocidContainerDirPathURL's URLByAppendingPathComponent:strNewFileName)
    ####リネームする
    set listResult to (appFileManager's moveItemAtURL:ocidFilePathURL toURL:ocidNewFilePathURL |error|:(reference))
    
  end if
  
end repeat


###########################################
### データレート と サンプルレートを読み取るサブ
###########################################
to doGetDataAndSampleRate(argURL)
  ####URLをAVAsset読み込み
  set ocidReadAsset to (refMe's AVAsset's assetWithURL:argURL)
  ## log ocidReadAsset's preferredRate()
  ##ファイルの長さ
  set ocidReadAssetDuration to ocidReadAsset's duration()
  set numTimeValue to (item 1 of ocidReadAssetDuration) as integer
  set numTimeScall to (item 2 of ocidReadAssetDuration) as integer
  set numMin to ((numTimeValue / numTimeScall) / 60) as number
  set strMin to doRound2Dec({numMin, 2, "up"}) as text
  
  
  ###トラック読み込み
  set ocidReadAssetTrackArray to ocidReadAsset's tracks()
  ###オーディオトラック読み込み
  set ocidTrack to (ocidReadAssetTrackArray's objectAtIndex:0)
  ###サンプルレート取得
  set numSampleRate to ocidTrack's naturalTimeScale() as integer
  set strSampleRate to (round (numSampleRate / 100) rounding down) as text
  ###データレート取得
  set ocidDataRate to ocidTrack's estimatedDataRate() as integer
  set numDataRate to ocidDataRate as integer
  #
  
  
  ###データレート0対策
  if numDataRate = 0 then
    set strArgFilePath to (argURL's |path|()) as text
    set strCommandText to ("/usr/bin/afinfo -i \"" & strArgFilePath & "\"") as text
log strCommandText
    try
      with timeout of 10 seconds
        set strResponse to (do shell script strCommandText) as text
      end timeout
    on error
return {0, strSampleRate}
    end try
    set AppleScript's text item delimiters to "\r"
    set listResponse to every text item of strResponse
    set AppleScript's text item delimiters to ""
    repeat with itemLineText in listResponse
      if itemLineText starts with "bit rate" then
        set AppleScript's text item delimiters to " "
        set listLineText to every text item of itemLineText
        set AppleScript's text item delimiters to ""
        set strDataRate to (round ((item 3 of listLineText) / 1000)) as text
        exit repeat
      end if
    end repeat
  else
    set strDataRate to (round (numDataRate / 1000)) as text
  end if
  ####値を戻す
return {strDataRate, strSampleRate, strMin}
end doGetDataAndSampleRate
##########################################
# 小数点以下桁揃え  数値 桁数 四捨五入 up or down
##########################################
to doRound2Dec({argNumNumber, argNumDecNo, argStrRound})
  set numNumber to argNumNumber as number
  set numDecNo to argNumDecNo as integer
  set strRound to argStrRound as text
  # 10のx乗 
  set numDec to (10 ^ numDecNo) as integer
  # ↑の数桁数だけ元の数値の桁数を増やして
  set numStep1 to (numNumber * numDec) as number
  # 数値の丸め 繰り上がりup と繰り下がりdownの処理
  if strRound is "up" then
    set numStep2 to (round of numStep1 rounding up) as integer
  else if strRound is "down" then
    set numStep2 to (round of numStep1 rounding down) as integer
  end if
  # 最後の桁数を戻して
  set numStep3 to (numStep2 / numDec) as number
  # テキストで戻す場合
  # set strStep3 to (numStep2 / numDec) as text
  # 数値で戻す
return numStep3
end doRound2Dec

|

[AVAsset]ビデオのサイズ(縦横サイズ)の取得


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "AVFoundation"
use framework "CoreMedia"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()



#############################
###入力ファイル
#############################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
####UTIリスト
set listUTI to {"public.movie"}
####ダイアログを出す
set aliasFilePath to (choose file with prompt "ムービーファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
###入力ファイル
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)


#############################
### ムービー読み込み
#############################
set ocidReadAsset to refMe's AVAsset's assetWithURL:(ocidFilePathURL)
set ocidReadAssetTrackArray to ocidReadAsset's tracks()
set ocidVideoTrack to ocidReadAssetTrackArray's firstObject()
#
set recordAssetTrackNaturalSize to ocidVideoTrack's naturalSize()
log recordAssetTrackNaturalSize
set numW to (width of recordAssetTrackNaturalSize) as integer
set numH to (height of recordAssetTrackNaturalSize) as integer

log "w:" & numW
log "h:" & numH
return

|

[AVAsset]ビデオの長さ 時間の取得


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "AVFoundation"
use framework "CoreMedia"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()



#############################
###入力ファイル
#############################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
####UTIリスト
set listUTI to {"public.movie"}
####ダイアログを出す
set aliasFilePath to (choose file with prompt "ムービーファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
###入力ファイル
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)

#############################
### ムービー読み込み
#############################
set ocidReadAsset to refMe's AVAsset's assetWithURL:(ocidFilePathURL)
set ocidReadAssetTrackArray to ocidReadAsset's tracks()
set ocidVideoTrack to ocidReadAssetTrackArray's firstObject()
#
set ocidAssetTrackTimeRange to ocidVideoTrack's timeRange()
set listTimeRange to (item 2 of ocidAssetTrackTimeRange)
set strSec to ((item 1 of listTimeRange) / (item 2 of listTimeRange)) as integer
#
set numH to (round of (strSec / 3600) rounding down)
set numM to (round of ((strSec - (numH * 3600)) / 60) rounding down)
set numS to strSec - (numH * 3600) - (numM * 60)

###ゼロサプレス
set strZeroSup to "00" as text
set strH to (text -2 through -1 of ("00" & numH)) as text
set strM to (text -2 through -1 of ("00" & numM)) as text
set strS to (text -2 through -1 of ("00" & numS)) as text

###戻り値
set strSStime to (strH & ":" & strM & ":" & strS) as text
log strSStime
set strMes to ("計算結果です: " & strSec & "秒は \r " & strSStime & "\r" & numH & "時間" & numM & "分" & numS & "秒\r" & strH & "時間" & strM & "分" & strS & "秒\r") as text

log strMes


return

|

[AVAsset]データレートbpsの取得


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "AVFoundation"
use framework "CoreMedia"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()



#############################
###入力ファイル
#############################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
####UTIリスト
set listUTI to {"public.movie"}
####ダイアログを出す
set aliasFilePath to (choose file with prompt "ムービーファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
###入力ファイル
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)

#############################
### ムービー読み込み
#############################
set ocidReadAsset to refMe's AVAsset's assetWithURL:(ocidFilePathURL)
set ocidReadAssetTrackArray to ocidReadAsset's tracks()
set ocidVideoTrack to ocidReadAssetTrackArray's firstObject()
#
set numDataRate to ocidVideoTrack's estimatedDataRate() as number
set numDataRate to (numDataRate / 1000) as integer
set strDataRate to numDataRate as text
log strDataRate
return

|

[AVAsset] フレームレートfpsの取得


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "AVFoundation"
use framework "CoreMedia"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()

#############################
###入力ファイル
#############################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
####UTIリスト
set listUTI to {"public.movie"}
####ダイアログを出す
set aliasFilePath to (choose file with prompt "ムービーファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
###入力ファイル
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)

#############################
### ムービー読み込み
#############################
set ocidReadAsset to refMe's AVAsset's assetWithURL:(ocidFilePathURL)
set ocidReadAssetTrackArray to ocidReadAsset's tracks()
set ocidVideoTrack to ocidReadAssetTrackArray's firstObject()
#
set ocidAssetTrackTimeRange to ocidVideoTrack's timeRange()
set listTimeRange to (item 2 of ocidAssetTrackTimeRange)
set strSec to ((item 1 of listTimeRange) / (item 2 of listTimeRange)) as integer

set numFlameRate to ocidVideoTrack's nominalFrameRate()
log numFlameRate
set ocidFormatter to refMe's NSNumberFormatter's alloc()'s init()
(ocidFormatter's setNumberStyle:(refMe's NSNumberFormatterDecimalStyle))
(ocidFormatter's setMinimumFractionDigits:(1))
(ocidFormatter's setMaximumFractionDigits:(1))
(ocidFormatter's setRoundingMode:(refMe's NSNumberFormatterRoundDown))
set strFlameRate to (ocidFormatter's stringFromNumber:(numFlameRate)) as text
log strFlameRate
return

|

[AVAsset]基本的な情報の取得


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AVFoundation"
use framework "AppKit"
use framework "CoreMedia"
use scripting additions
property refMe : a reference to current application
####################################
####ダイアログ 入力ビデオ
####################################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
set listUTI to {"public.movie"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル
  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
on error
  log "エラーしました"
return "エラーしました"
end try
set strFilePath to POSIX path of aliasFilePath
set ocidFilePath to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath)

####################################
####ダイアログ 出力フォルダ
####################################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set strMes to "フォルダを選んでください" as text
set strPrompt to "フォルダを選択してください" as text
try
  set aliasResponse to (choose folder strMes with prompt strPrompt default location aliasDefaultLocation without multiple selections allowed, invisibles and showing package contents) as alias
on error
  log "エラーしました"
return "エラーしました"
end try
set strSaveDirPath to POSIX path of aliasResponse
set ocidSaveDirPath to refMe's NSString's stringWithString:(strSaveDirPath)
set ocidSaveDirPathURL to refMe's NSURL's fileURLWithPath:(ocidSaveDirPath)

##########################################
######AVAsset
##########################################
set ocidReadAsset to refMe's AVAsset's assetWithURL:(ocidFilePathURL)
##Duration
set ocidReadAssetDuration to ocidReadAsset's duration()
log ocidReadAssetDuration as record
###総秒
set cmTime to refMe's CMTimeGetSeconds(ocidReadAssetDuration)
###時間
set numHours to (round of ((cmTime as number) / 3600) rounding down) as integer
###分
set numMinutes to (round of (((cmTime as number) - (numHours * 3600)) / 60) rounding down) as integer
###残り秒
set numSec to cmTime - ((numHours * 3600) + (numMinutes * 60))
log "時間:" & numHours & "時 " & numHours & "分 " & numSec & "秒"
######AVAssetTrackGroup
set ocidReadAssetTrackGArray to ocidReadAsset's trackGroups()
set numCntTrackG to (ocidReadAssetTrackGArray count) as integer
log "トラックグループ数: " & numCntTrackG
log ("トラックグループID: " & ((ocidReadAssetTrackGArray's firstObject())'s trackIDs() as integer)) as text

######AVAssetTrack
set ocidReadAssetTrackArray to ocidReadAsset's tracks()
set numCntTrack to (ocidReadAssetTrackArray count) as integer
log "トラック数は: " & numCntTrack
##
repeat with itemIntNo from 0 to (numCntTrack - 1) by 1
  set ocidTrack to (ocidReadAssetTrackArray's objectAtIndex:(itemIntNo))
  log className() of ocidTrack as text
  set strTrackID to ocidTrack's trackID() as text
  log strTrackID
  set strMediaType to ocidTrack's mediaType() as text
  if strMediaType is "vide" then
    ########################
    log "MediaType: vide ビデオトラック:トラックIDは" & strTrackID
    ## トラックの総時間
    set listAssetTrackTimeRange to ocidTrack's timeRange()
    set listStartTime to (item 1 of listAssetTrackTimeRange)
    set listDurationTime to (item 2 of listAssetTrackTimeRange)
    log listStartTime as list
    log listDurationTime as list
    ##タイムスケール
    set numAssetTrackTimeScale to ocidTrack's naturalTimeScale()
    log numAssetTrackTimeScale
    ##トラックの画面サイズ
    set recordAssetTrackNaturalSize to ocidTrack's naturalSize()
    log recordAssetTrackNaturalSize
    set numTrackWidth to (width of recordAssetTrackNaturalSize) as integer
    set numTrackHeight to (height of recordAssetTrackNaturalSize) as integer
    ##1フレームの長さ
    set recordCMTimeFrameDura to ocidTrack's minFrameDuration()
    set numFlameScale to ((value of recordCMTimeFrameDura) / (timescale of recordCMTimeFrameDura)) as number
    log numFlameScale
    set numFlameRateDura to (1 / numFlameScale)
    log numFlameRateDura
    ##フレームレート
    set numFlameRate to ocidTrack's nominalFrameRate() as number
    log numFlameRate
  else if strMediaType is "soun" then
    ########################
    log "MediaType: soun サウンドトラック:トラックIDは" & strTrackID
  end if
  
end repeat

|

[AVAsset]トラックグループ と トラック数


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AVFoundation"
use framework "AppKit"
use framework "CoreMedia"
use scripting additions
property refMe : a reference to current application
####################################
####ダイアログ
####################################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
set listUTI to {"public.movie"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル
  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
on error
  log "エラーしました"
return "エラーしました"
end try
set strFilePath to POSIX path of aliasFilePath
set ocidFilePath to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath)
######AVAsset
set ocidReadAsset to refMe's AVAsset's assetWithURL:(ocidFilePathURL)

######AVAssetTrackGroup
set ocidReadAssetTrackArray to ocidReadAsset's trackGroups()
set numCntTrackG to (ocidReadAssetTrackArray count) as integer
log "トラックグループ数: " & numCntTrackG
log ("トラックグループID: " & ((ocidReadAssetTrackArray's firstObject())'s trackIDs() as integer)) as text

######AVAssetTrack
set ocidReadAssetTrackArray to ocidReadAsset's tracks()
set numCntTrack to (ocidReadAssetTrackArray count) as integer
log "トラック数は: " & numCntTrack

|

[AVAsset]ビデオの時間


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AVFoundation"
use framework "AppKit"
use framework "CoreMedia"
use scripting additions
property refMe : a reference to current application
####################################
####ダイアログ
####################################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
set listUTI to {"public.movie"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル
  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
on error
  log "エラーしました"
return "エラーしました"
end try
set strFilePath to POSIX path of aliasFilePath
set ocidFilePath to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath)
######AVAsset
set ocidReadAsset to refMe's AVAsset's assetWithURL:(ocidFilePathURL)
##Duration
set ocidReadAssetDuration to ocidReadAsset's duration()
###総秒
set cmTime to refMe's CMTimeGetSeconds(ocidReadAssetDuration)
###時間
set numHours to (round of ((cmTime as number) / 3600) rounding down) as integer
###分
set numMinutes to (round of (((cmTime as number) - (numHours * 3600)) / 60) rounding down) as integer
###残り秒
set numSec to cmTime - ((numHours * 3600) + (numMinutes * 60))
log "時間:" & numHours & "時 " & numHours & "分 " & numSec & "秒"

######AVAssetTrack"


|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom