« SJIS2UTF考え中 | トップページ | [python3]fontTools »

[Fonts]ファミリー名のフォルダを作ってフォントを中に入れる

ダウンロード - フォント整理用ファミリー名.zip


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

#!/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 scripting additions
property refMe : a reference to current application

#######################
####exiftoolへのパス
#######################
tell application "Finder"
  set aliasPathToMe to (path to me) as alias
  set aliasContainerDir to (container of aliasPathToMe) as alias
  set aliasExifPath to (file "exiftool" of folder "bin" of folder aliasContainerDir) as alias
end tell
set strExifPath to (POSIX path of aliasExifPath) as text

#######################
####ダイアログ
#######################
set strUTI to {"public.font"}
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set listChooseFile to (choose file with prompt "フォントファイルを選んでください" default location aliasDefaultLocation of type strUTI with invisibles, multiple selections allowed and showing package contents) as list

#######################
####選択ファイルで繰返し
#######################

repeat with itemChooseFile in listChooseFile
  #######################
  ####パス
  #######################
  set aliasFilePath to itemChooseFile 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 ocidFileName to ocidFilePathURL's lastPathComponent()
  set ocidContainerDirURL to ocidFilePathURL's URLByDeletingLastPathComponent()
  set ocidBaseFileName to ocidFileName's stringByDeletingPathExtension()
  
  #######################
  ####コマンド実行
  #######################
  set strCommandText to ("\"" & strExifPath & "\" -json -charset UTF8 -lang Ja \"" & strFilePath & "\"") as text
  set jsonFontsExif to (do shell script strCommandText) as text
  
  #######################
  ####JSONをDATAに
  #######################
  set coidJsonString to (refMe's NSString's stringWithString:(jsonFontsExif))
  set ocidJsonData to (coidJsonString's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
  
  set listJsonData to (refMe's NSJSONSerialization's JSONObjectWithData:(ocidJsonData) options:(refMe's NSJSONReadingMutableContainers) |error|:(reference))
  set ocidJsonData to ((item 1 of listJsonData)'s objectAtIndex:0)
  
  #######################
  ####JSONをNSDictionary
  #######################
  set ocidJsonDict to (refMe's NSDictionary's alloc()'s initWithDictionary:(ocidJsonData))
  
  #######################
  #### Value
  #######################
  
  set strFontFamily to (ocidJsonDict's valueForKey:"PreferredFamily-ja") as text
  if strFontFamily is "missing value" then
    set strFontFamily to (ocidJsonDict's valueForKey:"FontFamily-ja") as text
  end if
  if strFontFamily contains "?" then
    set strFontFamily to (ocidJsonDict's valueForKey:"FontFamily-ja") as text
  end if
  
  if strFontFamily is "missing value" then
    set strFontFamily to (ocidJsonDict's valueForKey:"PreferredFamily-en-US") as text
  end if
  if strFontFamily is "missing value" then
    set strFontFamily to (ocidJsonDict's valueForKey:"FontFamily-en-US") as text
  end if
  if strFontFamily contains "?" then
    set strFontFamily to (ocidJsonDict's valueForKey:"FontFamily-en-US") as text
  end if
  
  if strFontFamily is "missing value" then
    set strFontFamily to (ocidJsonDict's valueForKey:"PreferredFamily") as text
  end if
  if strFontFamily is "missing value" then
    set strFontFamily to (ocidJsonDict's valueForKey:"FontFamily") as text
  end if
  if strFontFamily contains "?" then
    set strFontFamily to (ocidJsonDict's valueForKey:"FontFamily") as text
  end if
  if strFontFamily is "missing value" then
    set strFontFamily to ocidBaseFileName as text
  end if
  if strFontFamily contains "?" then
    set strFontFamily to ocidBaseFileName as text
  end if
  set strDirName to strFontFamily as text
  
  #######################
  set strFontName to (ocidJsonDict's valueForKey:"FontName-ja") as text
  if strFontName is "missing value" then
    set strFontName to (ocidJsonDict's valueForKey:"FontName-en-US") as text
  end if
  if strFontName contains "?" then
    set strFontName to (ocidJsonDict's valueForKey:"FontName-en-US") as text
  end if
  if strFontName is "missing value" then
    set strFontName to (ocidJsonDict's valueForKey:"FontName") as text
  end if
  if strFontName contains "?" then
    set strFontName to (ocidJsonDict's valueForKey:"FontName") as text
  end if
  #######
  set strPostScriptFontName to (ocidJsonDict's valueForKey:"PostScriptFontName") as text
  #######
  
  ###################################
  ##### 移動先フォルダ
  ###################################
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidDirPathURL to (ocidContainerDirURL's URLByAppendingPathComponent:(strDirName) isDirectory:true)
  set boolMakeDir to (appFileManager's createDirectoryAtURL:(ocidDirPathURL) withIntermediateDirectories:true attributes:(missing value) |error|:(reference))
  ###################################
  ##### 移動
  ###################################
  set ocidDistPathURL to (ocidDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:false)
  set boolMoveFile to (appFileManager's moveItemAtURL:(ocidFilePathURL) toURL:(ocidDistPathURL) |error|:(missing value))
  
  
  
end repeat




|

« SJIS2UTF考え中 | トップページ | [python3]fontTools »

AppleScript Fonts」カテゴリの記事

AppleScript EXIFData」カテゴリの記事