« [Movie]ファイル名変更(wxhとfps入り) | トップページ | [Jedit]重複行削除 »

[Font]フォントをファミリー名フォルダに整理

フォント-->ファミリー名-->フォルダ作成 -->フォントをフォルダに入れる
PreferredFamily名
FontFamily名

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
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 refNSMutableString : a reference to refMe's NSMutableString
property refNSData : a reference to refMe's NSData
property refNSURL : a reference to refMe's NSURL
property refNSDictionary : a reference to refMe's NSDictionary
property refNSMutableDictionary : a reference to refMe's NSMutableDictionary
property refNSJSONSerialization : a reference to refMe's NSJSONSerialization

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


#####設定項目
####exiftoolへのパス
set strExifPath to "$HOME/bin/exiftool/exiftool"
########################################
#######前準備
##このファイルへのパスとコンテナ
tell application "Finder"
set aliasPathToMe to (path to me) as alias
set aliasPathToMeDir to (container of aliasPathToMe) as alias
end tell
set strPathToMePath to (POSIX path of aliasPathToMe) as text
set strPathToMeDirPath to (POSIX path of aliasPathToMeDir) as text
########################################
#######ファイル選択
---プロンプトの文言改行が使えます\nを入れます
set theWithPrompt to "ファイルを選択してください"
---ファイル選択ダイアログのデフォルトのディレクトリ
set aliasDefaultLocation to path to desktop folder from user domain
set theFileTypeList to {"public.font"}
---ダイアログを出して選択されたファイルは「open」に渡す
set listAliasFilePath to (choose file default location aliasDefaultLocation ¬
with prompt theWithPrompt ¬
of type theFileTypeList ¬
invisibles false ¬
with multiple selections allowed without showing package contents) as list



repeat with itemAliasFilePath in listAliasFilePath

set strFontFamily to "" as text


####入力ファイル関連
set strFilePath to (POSIX path of itemAliasFilePath) as text
###NSストリングに
set ocidFilePath to (refNSString's stringWithString:strFilePath)
###NSURL
set ocidFilePathURL to (refMe's NSURL's fileURLWithPath:ocidFilePath)
##ファイル名取得
set strFileName to (ocidFilePathURL's lastPathComponent) as text
###コンテネ
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
########################################
###データ取得
try
set theCommandText to ("\"" & strExifPath & "\" -json \"" & strFilePath & "\"") as text
set strResponseJosn to (do shell script theCommandText) as text
on error
log "たぶんexiftoolの非対応のファイルタイプです"
end try

###テキストに
set ocidReadDataJson to (refNSString's stringWithString:strResponseJosn)
###UTF8データに
set ocidReadDataUTF to (ocidReadDataJson's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
###データ初期化
set ocidReadData to (refNSData's alloc()'s initWithData:ocidReadDataUTF)
###JSON初期化
set listJSONSerialization to (refNSJSONSerialization's JSONObjectWithData:ocidReadData options:0 |error|:(reference))
####レコードを取得します
set ocidJsonData to item 1 of listJSONSerialization
-->(*__NSSingleObjectArrayI*)
set ocidJsonDict to (item 1 of ocidJsonData)
-->(*__NSDictionaryI*)
####レコードをNSDictionaryとして格納
set ocidJsonResponse to (refNSDictionary's alloc()'s initWithDictionary:ocidJsonDict)
########################################
try
set strFontFamily to |PreferredFamily-ja| of ocidJsonResponse as text
on error
try
set strFontFamily to |PreferredFamily| of ocidJsonResponse as text
on error
try
set strFontFamily to |PreferredFamily-en-US| of ocidJsonResponse as text
on error
try
set strFontFamily to |FontFamily| of ocidJsonResponse as text
on error
set strFontFamily to |FontFamily-en-US| of ocidJsonResponse as text
end try
end try
end try
end try



################################
###
set ocidMakeDirPathURL to (ocidContainerDirPathURL's URLByAppendingPathComponent:strFontFamily)
###作るフォルダ
(*
###主要なモード NSFilePosixPermissions
777-->511
775-->509
770-->504
755-->493
750-->488
700-->448
555-->365
333-->219
#####NSFileGroupOwnerAccountID
ゲストのGID
201-->_guest
99-->_unknown
-2-->nobody
*)
set boolMakeNewFolder to (objFileManager's createDirectoryAtURL:ocidMakeDirPathURL withIntermediateDirectories:true attributes:({NSFilePosixPermissions:493}) |error|:(reference))
if boolMakeNewFolder is false then
log "失敗しました"
end if
set ocidDistPathURL to (ocidMakeDirPathURL's URLByAppendingPathComponent:strFileName)
log ocidDistPathURL as text
set boolMoveFileAndRename to (objFileManager's moveItemAtURL:ocidFilePathURL toURL:ocidDistPathURL |error|:(reference))
if boolMoveFileAndRename is false then
log "失敗しました"
end if




end repeat


#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
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 refNSMutableString : a reference to refMe's NSMutableString
property refNSData : a reference to refMe's NSData
property refNSURL : a reference to refMe's NSURL
property refNSDictionary : a reference to refMe's NSDictionary
property refNSMutableDictionary : a reference to refMe's NSMutableDictionary
property refNSJSONSerialization : a reference to refMe's NSJSONSerialization

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


#####設定項目
####exiftoolへのパス
set strExifPath to "$HOME/bin/exiftool/exiftool"
########################################
#######前準備
##このファイルへのパスとコンテナ
tell application "Finder"
set aliasPathToMe to (path to me) as alias
set aliasPathToMeDir to (container of aliasPathToMe) as alias
end tell
set strPathToMePath to (POSIX path of aliasPathToMe) as text
set strPathToMeDirPath to (POSIX path of aliasPathToMeDir) as text
########################################
#######ファイル選択
---プロンプトの文言改行が使えます\nを入れます
set theWithPrompt to "ファイルを選択してください"
---ファイル選択ダイアログのデフォルトのディレクトリ
set aliasDefaultLocation to path to desktop folder from user domain
set theFileTypeList to {"public.font"}
---ダイアログを出して選択されたファイルは「open」に渡す
set listAliasFilePath to (choose file default location aliasDefaultLocation ¬
with prompt theWithPrompt ¬
of type theFileTypeList ¬
invisibles false ¬
with multiple selections allowed without showing package contents) as list



repeat with itemAliasFilePath in listAliasFilePath

set strFontFamily to "" as text


####入力ファイル関連
set strFilePath to (POSIX path of itemAliasFilePath) as text
###NSストリングに
set ocidFilePath to (refNSString's stringWithString:strFilePath)
###NSURL
set ocidFilePathURL to (refMe's NSURL's fileURLWithPath:ocidFilePath)
##ファイル名取得
set strFileName to (ocidFilePathURL's lastPathComponent) as text
###コンテネ
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
########################################
###データ取得
try
set theCommandText to ("\"" & strExifPath & "\" -json \"" & strFilePath & "\"") as text
set strResponseJosn to (do shell script theCommandText) as text
on error
log "たぶんexiftoolの非対応のファイルタイプです"
end try

###テキストに
set ocidReadDataJson to (refNSString's stringWithString:strResponseJosn)
###UTF8データに
set ocidReadDataUTF to (ocidReadDataJson's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
###データ初期化
set ocidReadData to (refNSData's alloc()'s initWithData:ocidReadDataUTF)
###JSON初期化
set listJSONSerialization to (refNSJSONSerialization's JSONObjectWithData:ocidReadData options:0 |error|:(reference))
####レコードを取得します
set ocidJsonData to item 1 of listJSONSerialization
-->(*__NSSingleObjectArrayI*)
set ocidJsonDict to (item 1 of ocidJsonData)
-->(*__NSDictionaryI*)
####レコードをNSDictionaryとして格納
set ocidJsonResponse to (refNSDictionary's alloc()'s initWithDictionary:ocidJsonDict)
########################################
try
set strFontFamily to |PreferredFamily-ja| of ocidJsonResponse as text
on error
try
set strFontFamily to |FontFamily| of ocidJsonResponse as text
on error
try
set strFontFamily to |FontFamily-en-US| of ocidJsonResponse as text
on error
try
set strFontFamily to |PreferredFamily| of ocidJsonResponse as text
on error
set strFontFamily to |PreferredFamily-en-US| of ocidJsonResponse as text

end try
end try
end try
end try



################################
###
set ocidMakeDirPathURL to (ocidContainerDirPathURL's URLByAppendingPathComponent:strFontFamily)
###作るフォルダ
(*
###主要なモード NSFilePosixPermissions
777-->511
775-->509
770-->504
755-->493
750-->488
700-->448
555-->365
333-->219
#####NSFileGroupOwnerAccountID
ゲストのGID
201-->_guest
99-->_unknown
-2-->nobody
*)
set boolMakeNewFolder to (objFileManager's createDirectoryAtURL:ocidMakeDirPathURL withIntermediateDirectories:true attributes:({NSFilePosixPermissions:493}) |error|:(reference))
if boolMakeNewFolder is false then
log "失敗しました"
end if
set ocidDistPathURL to (ocidMakeDirPathURL's URLByAppendingPathComponent:strFileName)
log ocidDistPathURL as text
set boolMoveFileAndRename to (objFileManager's moveItemAtURL:ocidFilePathURL toURL:ocidDistPathURL |error|:(reference))
if boolMoveFileAndRename is false then
log "失敗しました"
end if




end repeat

|

« [Movie]ファイル名変更(wxhとfps入り) | トップページ | [Jedit]重複行削除 »

AppleScript Fonts」カテゴリの記事