« [NSimage] イメージデータをPDFに変換 | トップページ | [NSURLVolumeIsInternalKey]ボリュームの種別を取得 »

[eyeD3]MP3のタイトルをファイル名に設定する

#!/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 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 refAVAsset : a reference to refMe's AVAsset
property refAVURLAsset : a reference to refMe's AVURLAsset
property refAVMetadataItem : a reference to refMe's AVMetadataItem

set objFileManager to refMe's NSFileManager's defaultManager()


###eyeD3へのパス
set strBinPath to (do shell script "echo $HOME/Library/Python/3.9/bin/eyeD3") as text

#####ファイル選択ダイアログ
tell application "Finder"
##set aliasDefaultLocation to container of (path to me) as alias
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
end tell
set listChooseFileUTI to {"public.mp3", "com.apple.m4a-audio"}
set strPromptText to "音楽ファイルを選んでください" as text
set listAliasFilePath to (choose file with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with invisibles and multiple selections allowed without showing package contents)


#####本処理
repeat with objAliasFilePath in listAliasFilePath
###ファイルパスからファイル名を取得
set strFilePath to POSIX path of objAliasFilePath as text
set ocidFilePath to (refNSString's stringWithString:strFilePath)
set ocidFilePathURL to (refNSURL's alloc()'s initFileURLWithPath:ocidFilePath)
set ocidFileName to ocidFilePathURL's lastPathComponent
set strPrefixName to (ocidFileName's stringByDeletingPathExtension) as text

###コマンド整形
set strCommandText to "\"" & strBinPath & "\" -t \"" & strPrefixName & "\" \"" & strFilePath & "\"" as text
###実行
do shell script strCommandText
####結果を確認
set ocidAVURLAsset to (refAVURLAsset's URLAssetWithURL:ocidFilePathURL options:(missing value))
set ocidCommonMetadata to ocidAVURLAsset's commonMetadata()
set ocidTitleArray to (refAVMetadataItem's metadataItemsFromArray:ocidCommonMetadata withKey:(refMe's AVMetadataCommonKeyTitle) keySpace:(refMe's AVMetadataKeySpaceCommon))
set ocidMetaTitle to (ocidTitleArray's objectAtIndex:0)
set strGetTitle to ocidMetaTitle's value() as text

if strGetTitle is strPrefixName then
log "書き換え成功"
else
log "書き換え失敗"
end if
end repeat

|

« [NSimage] イメージデータをPDFに変換 | トップページ | [NSURLVolumeIsInternalKey]ボリュームの種別を取得 »

AppleScript Python」カテゴリの記事

AppleScript Music」カテゴリの記事