AppleScript Icon

[icon]アイコン関連 自分まとめ

アイコン関連カテゴリー
https://quicktimer.cocolog-nifty.com/icefloe/cat76054220/index.html



Icons001_20240222130401

1:正方形の元画像を作っておく
2:Iconsetを生成する
https://quicktimer.cocolog-nifty.com/icefloe/2023/07/post-1e40b1.html
3:IconsetからIcnsファイルを作成する
https://quicktimer.cocolog-nifty.com/icefloe/2024/02/post-afd516.html
3:Iconsetからcarファイルを作成する
XcodeかAsset Catalog Creator等を利用して作成する
3:IconsetからWindowsIcoファイルを作成する
いわゆるfavicon.ico用です
16x16と32x32を使いますが、用途の特性上『別に作る』ことをお勧めする


A:icns(Apple Icon Image)ファイル
B:car(Asset Catalog)ファイル
C:ico(Windows Icon Image)ファイル
D:png他 WEBサイト アプリアイコン用ファイル
F:コマンド
G:ツール類
H:マテリアル(素材)


A:icns(Apple Icon Image)ファイル
プレビュー.appからも作成可能ですが
iconutilを利用するのがいいでしょう
手順
1:iconset各種サイズの画像を生成しておく
ICONに必要なサイズの画像を生成する(167サイズ修正)
https://quicktimer.cocolog-nifty.com/icefloe/2023/07/post-1e40b1.html
2:iconutil
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-61befa.html
iconutilでICNSファイルに変換する
https://quicktimer.cocolog-nifty.com/icefloe/2024/02/post-afd516.html


B:car(Asset Catalog)ファイル
作成:XCode
https://apps.apple.com/jp/app/xcode/id497799835?mt=12
Asset Catalog Creator
https://apps.apple.com/jp/app/asset-catalog-creator/id866571115?mt=12
書出:iconutil acextractコマンドを使って書出



C:ico(Windows Icon Image)ファイル
W16px H16px 256色まで(昔ながら)
最近は
16x16、32x32 のマルチサイズICOファイルが主流?
faviconを作る
https://quicktimer.cocolog-nifty.com/icefloe/2023/12/post-2f0d4e.html
透過が反映されない事と
素材を別途作成しておいて
用途が少し違うので別途デザインする事をお勧めする
GraphicConverterを使って書き出すのがおすすめ
https://www.lemkesoft.de/en/products/graphicconverter/
FireFox等icoファイルを優先して表示するブラウザもありますので
用意しておいてもバチは当たらない程度です
基本的にはpng画像等で用意しておけばfavicon.icoファイル自体は不要な場面が多いです。
20240224044131910x362


D:png他 WEBサイト アプリアイコン用ファイル
各種サイズがあります デザインテンプレートを参照のこと
https://developer.apple.com/design/resources/
Sketchが必須
https://www.sketch.com/apps/




F:コマンド
/usr/bin/iconutil
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-61befa.html

acextract
https://github.com/bartoszj/acextract
Assets.carからの全イメージ書き出し
https://quicktimer.cocolog-nifty.com/icefloe/2023/10/post-76f605.html



G:ツール類
GraphicConverter (ico Windows icon imageを作成できます)
https://www.lemkesoft.de/en/products/graphicconverter/
Cartools (carファイルから画像等を書き出せます)
https://github.com/showxu/cartools
AssetCatalogTinkerer(carファイルから画像等を書き出せます)
https://github.com/insidegui/AssetCatalogTinkerer
Sketch(Appleのテンプレートを使用するのに必要)
https://www.sketch.com/apps/
figma
https://www.figma.com/@apple


H:マテリアル(素材)
macos13 デフォルト フォルダーアイコン
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-aa0274.html
[Icon]GenericFolderIconV3 OS標準のフォルダーイメージを取得する
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-aa0274.html
サイズは 16,32,64,128,256,512,1024
Screen_20240211165001




アイコンファイルの生成
アプリケーションのアイコンを書き出す
https://quicktimer.cocolog-nifty.com/icefloe/2023/12/post-31c6d3.html
[Icon]アプリケーションのアイコン付きのフォルダを作成する
https://quicktimer.cocolog-nifty.com/icefloe/2024/02/post-19d852.html


フォルダにアイコン付与(画像選択)
https://quicktimer.cocolog-nifty.com/icefloe/2023/08/post-4b98e4.html
エイリアス作成とアイコン付与
https://quicktimer.cocolog-nifty.com/icefloe/2023/06/post-197f1d.html
書類アイコンに画像合成
書類アイコンに画像を合成する
https://quicktimer.cocolog-nifty.com/icefloe/2024/02/post-e4e5d7.html

|

[NSISIconImageRep]書類のデフォルトアプリの書類ICONSを取得生成


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(* com.cocolog-nifty.quicktimer.icefloe
選択したファイルの
OS標準のアイコンを取得し
iconset画像を生成して
ICNSファイルにします
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()
#############################
###ダイアログを前面に出す
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
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.data"}
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) 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 ocidContainerDirPath to ocidFilePath's stringByDeletingLastPathComponent()
set ocidIconFilePathURL to ocidFilePathURL's URLByAppendingPathExtension:("icns")
# NSISIconImageRep を取り出す
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set ocidIconImage to appSharedWorkspace's iconForFile:(ocidFilePath)
# コンテンツタイプ の取得
set ocidKey to (refMe's NSURLContentTypeKey)
set listRresourceValue to ocidFilePathURL's getResourceValue:(reference) forKey:(ocidKey) |error|:(reference)
set ocidContentType to (item 2 of listRresourceValue)
set ocidUTI to ocidContentType's identifier()
# デフォルトのアプリケーションの取得
set ocidAppURL to appSharedWorkspace's URLForApplicationToOpenContentType:(ocidContentType)
log ocidAppURL's absoluteString() as text
#デフォルトアプリケーションのバンドルID
set ocidBunndle to refMe's NSBundle's bundleWithURL:(ocidAppURL)
set ocidBunndleID to ocidBunndle's bundleIdentifier()
#保存先確保
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidPicturesDirPathURL to ocidURLsArray's firstObject()
set ocidParentDirPathURL to ocidPicturesDirPathURL's URLByAppendingPathComponent:("Icons/AppIcon") isDirectory:(true)
set ocidAppDirPathURL to ocidParentDirPathURL's URLByAppendingPathComponent:(ocidBunndleID) isDirectory:(true)
#通常用
set strSetValue to ((ocidUTI as text) & ".iconset") as text
set ocidSaveDirPathURL to ocidAppDirPathURL's URLByAppendingPathComponent:(strSetValue) isDirectory:(true)
#ダーク用
set strSetValue to ((ocidUTI as text) & "_Dark.iconset") as text
set ocidSaveDarkDirPathURL to ocidAppDirPathURL's URLByAppendingPathComponent:(strSetValue) isDirectory:(true)
#フォルダを作っておく
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
#通常用フォルダ
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
#ダーク用フォルダ
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDarkDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
########################
# Iconset作成開始
set ocidImageRepArray to ocidIconImage's representations()
set numCntDark to 0 as integer
repeat with itemImageRep in ocidImageRepArray
  #サイズ
  set ocidImageSize to itemImageRep's |size|()
  set numPointWide to (ocidImageSize's width) as integer
  set numPointHigh to (ocidImageSize's height) as integer
  #ピクセルサイズ
  set numPixelsWide to itemImageRep's pixelsWide() as integer
  set numPixelsHigh to itemImageRep's pixelsHigh() as integer
  #解像度の指数
  set numRatio to (numPixelsWide / numPointWide) as integer
  set numISIconImageRepWide to (numPointWide * numRatio) as integer
  set numISIconImageRepHigh to (numPointHigh * numRatio) as integer
  
  #保存用の解像度を加味したサイズ
  set ocidRatioSize to refMe's NSMakeSize(numPointWide, numPointHigh)
  #合成位置
  set ocidDrawRect to refMe's NSMakeRect(0, 0, numPixelsWide, numPixelsHigh)
  #アイコンデータ画像の読み取り位置
  set ocidFromRect to refMe's NSMakeRect(0, 0, numPointWide, numPointHigh)
  ########################
  # 生成画像のサイズ
  set ocidAardboardSize to refMe's NSMakeSize(numPixelsWide, numPixelsHigh)
  # 保存される画像を生成
  set ocidAardboardImage to (refMe's NSImage's alloc()'s initWithSize:(ocidAardboardSize))
  # 画像生成
  set ocidAardboardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numPixelsWide) pixelsHigh:(numPixelsHigh) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSAlphaFirstBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
  ########################
  # 画像合成の始まり
  set ocidGraphicsContext to refMe's NSGraphicsContext
ocidGraphicsContext's saveGraphicsState()
  #コンテキストはアートボード保存用の画像
(ocidGraphicsContext's setCurrentContext:(ocidGraphicsContext's graphicsContextWithBitmapImageRep:(ocidAardboardRep)))
  #↑このコンテキストに読み込んだアイコンイメージを合成する
(itemImageRep's drawInRect:(ocidDrawRect) fromRect:(ocidFromRect) operation:(refMe's NSCompositeSourceOver) fraction:1.0 respectFlipped:false hints:(missing value))
  #画像合成の終わり
ocidGraphicsContext's restoreGraphicsState()
  
  #出来上がった画像に解像度を付与
(ocidAardboardRep's setSize:(ocidRatioSize))
  #解像度の違いによるファイル名の相違
  if numRatio = 1 then
    set strFileName to ("icon_" & numPixelsWide & "x" & numPixelsHigh) as text
  else
    set strFileName to ("icon_" & numPixelsWide & "x" & numPixelsHigh & "@" & numRatio & "x") as text
  end if
  #保存用のPNGフォーマットのプロパティ
  set ocidProperties to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidProperties's setObject:(2.2) forKey:(refMe's NSImageGamma))
(ocidProperties's setObject:(0) forKey:(refMe's NSImageInterlaced))
  set ocidType to (refMe's NSBitmapImageFileTypePNG)
  set ocidSaveData to (ocidAardboardRep's representationUsingType:(ocidType) |properties|:(ocidProperties))
  set ocidOption to (refMe's NSDataWritingAtomic)
  
  if numCntDark = 0 then
    #保存先URL 通常用
    set ocidSaveBaseFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:(false))
    set ocidSaveFilePathURL to (ocidSaveBaseFilePathURL's URLByAppendingPathExtension:("png"))
    set numCntDark to numCntDark + 1 as integer
  else if numCntDark = 1 then
    #保存先URL ダーク用
    set ocidSaveBaseFilePathURL to (ocidSaveDarkDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:(false))
    set ocidSaveFilePathURL to (ocidSaveBaseFilePathURL's URLByAppendingPathExtension:("png"))
    set numCntDark to 0 as integer
  end if
  set listDone to (ocidSaveData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error|:(reference))
  
end repeat
########################
#icnsファイル生成開始

#入力フォルダパス
set strSaveDirPath to (ocidSaveDirPathURL's |path|()) as text
set strSaveDarkDirPath to (ocidSaveDarkDirPathURL's |path|()) as text
#出力ファイルURL
set ocidSaveIconsFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:("DocIcon.icns") isDirectory:(false))
set ocidSaveDarkIconsFilePathURL to (ocidSaveDarkDirPathURL's URLByAppendingPathComponent:("DocIcon.icns") isDirectory:(false))
#出力ファイルパス
set strSaveIconsFilePath to (ocidSaveIconsFilePathURL's |path|()) as text
set strSaveDarkIconsFilePath to (ocidSaveDarkIconsFilePathURL's |path|()) as text
#コマンド実行
set strCommandText to ("/usr/bin/iconutil --convert icns \"" & strSaveDirPath & "/\" -o \"" & strSaveIconsFilePath & "\"") as text
do shell script strCommandText
set strCommandText to ("/usr/bin/iconutil --convert icns \"" & strSaveDarkDirPath & "/\" -o \"" & strSaveDarkIconsFilePath & "\"") as text
do shell script strCommandText


###保存先を開く
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set ocidOpenURLsArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:0)
(ocidOpenURLsArray's addObject:(ocidSaveDarkDirPathURL))
(ocidOpenURLsArray's addObject:(ocidSaveDirPathURL))
appSharedWorkspace's activateFileViewerSelectingURLs:(ocidOpenURLsArray)








|

ICONに必要なサイズの画像を生成する(サイズ追加) 修正

元画像が正方形以外の場合停止する処理を加えた

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

#!/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 "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions

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

set listSize to {16, 32, 40, 58, 60, 64, 76, 80, 87, 114, 120, 128, 136, 152, 167, 180, 192, 256, 512, 1024} as list
set list2xSize to {32, 40, 58, 64, 76, 80, 120, 136, 152, 167, 256, 512, 1024} as list
set list3xSize to {60, 87, 114, 120, 180, 192} as list

####################################
#合成するアイコンを選択する
####################################
###ダイアログ
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 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.image", "public.tiff", "public.jpeg", "public.png"}
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) as text
set ocidFilePath to refMe's NSString's stringWithString:(strFilePath)
set ocidImageFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath)
set ocidBaseFilePathURL to ocidImageFilePathURL's URLByDeletingPathExtension()
set ocidFileName to ocidBaseFilePathURL's lastPathComponent()
############################
### Retinaチェック
set ocidScreenArray to refMe's NSScreen's screens()
set appMainScreen to refMe's NSScreen's mainScreen()
set ocidDescription to appMainScreen's deviceDescription()
set recordDeviceResolution to refMe's NSSizeFromCGSize(ocidDescription's valueForKey:(refMe's NSDeviceResolution))
set intDeviceResolution to width of recordDeviceResolution as integer
if intDeviceResolution ≥ 144 then
  set boolRetina to true as boolean
log "Retinaディスプレイです"
else
  set boolRetina to false as boolean
end if
log "解像度:" & intDeviceResolution
#
####################################
#
####################################
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidPicturesDirPathURL to ocidURLsArray's firstObject()
set strSubPath to ("Icons/UserIcon") as text
set ocidSaveUserIconDirPathURL to (ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath))
set ocidSaveBaseDirPathURL to ocidSaveUserIconDirPathURL's URLByAppendingPathComponent:(ocidFileName)
set ocidIconSaveDirPathURL to ocidSaveBaseDirPathURL's URLByAppendingPathExtension:("iconset")
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidIconSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
#
##NSIMAGEに読み込む
set ocidReadImage to refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidImageFilePathURL)
set ocidImageRepArray to ocidReadImage's representations()
set ocidImageRep to (ocidImageRepArray's objectAtIndex:0)
##ピクセルサイズを取得
set numpixelsWidth to ocidImageRep's pixelsWide()
set numpixelsHeight to ocidImageRep's pixelsHigh()
#画像が正方形でない場合はここで終了
if numpixelsWidth ≠ numpixelsHeight then
return "正方形画像以外はアイコンで適しません"
end if

##まずは72ppiにする
set recordNewImageSize to {width:numpixelsWidth, height:numpixelsHeight} as record
(ocidImageRep's setSize:recordNewImageSize)
##ピクセルサイズ=ポイントサイズに変換
set ocidPixelsSize to refMe's NSMakeSize(numpixelsWidth, numpixelsWidth)
set ocidAddImage to refMe's NSImage's alloc()'s initWithSize:(ocidPixelsSize)
ocidAddImage's addRepresentation:(ocidImageRep)
##ポイントサイズを取得
set ocidImageRepSize to ocidImageRep's |size|()
set numPointWidth to width of ocidImageRepSize
set numPointHeight to height of ocidImageRepSize

####共通 保存オプション
set ocidProperty to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidProperty's setObject:(refMe's NSNumber's numberWithBool:false) forKey:(refMe's NSImageInterlaced))
(ocidProperty's setObject:(refMe's NSNumber's numberWithDouble:(1 / 2.2)) forKey:(refMe's NSImageGamma))


############################################
##サイズ
repeat with itemSize in listSize
  set itemSize to itemSize as integer
  if list2xSize contains itemSize then
    set int2xSize to (itemSize / 2) as integer
    set str2xFileName to ("icon_" & (int2xSize) & "x" & (int2xSize) & "@2x.png") as text
    set ocid2xSaveFilePathURL to (ocidIconSaveDirPathURL's URLByAppendingPathComponent:(str2xFileName) isDirectory:false)
    #####
    if boolRetina is true then
      ##解像度
      set intNewWidth to (itemSize / 2) as integer
      set intNewHeight to (itemSize / 2) as integer
    else
      set intNewWidth to (itemSize) as integer
      set intNewHeight to (itemSize) as integer
    end if
    ##サイズ
    set ocidNewImageSize to refMe's NSMakeSize(intNewWidth, intNewHeight)
    ##画像生成
    set ocidNewImage to (refMe's NSImage's alloc()'s initWithSize:(ocidNewImageSize))
    ##合成
ocidNewImage's lockFocus()
    set ocidNewRect to refMe's NSMakeRect(0, 0, intNewWidth, intNewHeight)
(ocidAddImage's drawInRect:(ocidNewRect) fromRect:(refMe's NSZeroRect) operation:(refMe's NSCompositeCopy) fraction:(1.0))
ocidNewImage's unlockFocus()
    ##imageRepに
    set ocidNewImageRep to ocidNewImage's TIFFRepresentation()
    set ocidSaveImageRep to (refMe's NSBitmapImageRep's imageRepWithData:(ocidNewImageRep))
    ##解像度
    set ocidNewImageSize to refMe's NSMakeSize((itemSize / 2), (itemSize / 2))
(ocidSaveImageRep's setSize:ocidNewImageSize)
    ##保存
    set ocidNSInlineData to (ocidSaveImageRep's representationUsingType:(refMe's NSBitmapImageFileTypePNG) |properties|:(missing value))
    set boolDone to (ocidNSInlineData's writeToURL:(ocid2xSaveFilePathURL) atomically:true)
    
  else if list3xSize contains itemSize then
    set int3xSize to (itemSize / 3) as integer
    set str3xFileName to ("icon_" & (int3xSize) & "x" & (int3xSize) & "@3x.png") as text
    set ocid3xSaveFilePathURL to (ocidIconSaveDirPathURL's URLByAppendingPathComponent:(str3xFileName) isDirectory:false)
    #####
    if boolRetina is true then
      ##解像度
      set intNewWidth to (itemSize / 2) as integer
      set intNewHeight to (itemSize / 2) as integer
    else
      set intNewWidth to (itemSize) as integer
      set intNewHeight to (itemSize) as integer
    end if
    ##サイズ
    set ocidNewImageSize to refMe's NSMakeSize(intNewWidth, intNewHeight)
    ##画像生成
    set ocidNewImage to (refMe's NSImage's alloc()'s initWithSize:(ocidNewImageSize))
    ##合成
ocidNewImage's lockFocus()
    set ocidNewRect to refMe's NSMakeRect(0, 0, intNewWidth, intNewHeight)
(ocidAddImage's drawInRect:(ocidNewRect) fromRect:(refMe's NSZeroRect) operation:(refMe's NSCompositeCopy) fraction:(1.0))
ocidNewImage's unlockFocus()
    ##imageRepに
    set ocidNewImageRep to ocidNewImage's TIFFRepresentation()
    set ocidSaveImageRep to (refMe's NSBitmapImageRep's imageRepWithData:(ocidNewImageRep))
    ##解像度
    set ocidNewImageSize to refMe's NSMakeSize((itemSize / 3), (itemSize / 3))
(ocidSaveImageRep's setSize:ocidNewImageSize)
    ##保存
    set ocidNSInlineData to (ocidSaveImageRep's representationUsingType:(refMe's NSBitmapImageFileTypePNG) |properties|:(missing value))
    set boolDone to (ocidNSInlineData's writeToURL:(ocid3xSaveFilePathURL) atomically:true)
  else
    set strFileName to ("icon_" & itemSize & "x" & itemSize & ".png") as text
    set ocidSaveFilePathURL to (ocidIconSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false)
    #####
    if boolRetina is true then
      ##解像度
      set intNewWidth to (itemSize / 2) as integer
      set intNewHeight to (itemSize / 2) as integer
    else
      set intNewWidth to (itemSize) as integer
      set intNewHeight to (itemSize) as integer
    end if
    ##サイズ
    set ocidNewImageSize to refMe's NSMakeSize(intNewWidth, intNewHeight)
    ##画像生成
    set ocidNewImage to (refMe's NSImage's alloc()'s initWithSize:(ocidNewImageSize))
    ##合成
ocidNewImage's lockFocus()
    set ocidNewRect to refMe's NSMakeRect(0, 0, intNewWidth, intNewHeight)
(ocidAddImage's drawInRect:(ocidNewRect) fromRect:(refMe's NSZeroRect) operation:(refMe's NSCompositeCopy) fraction:(1.0))
ocidNewImage's unlockFocus()
    ##imageRepに
    set ocidNewImageRep to ocidNewImage's TIFFRepresentation()
    set ocidSaveImageRep to (refMe's NSBitmapImageRep's imageRepWithData:(ocidNewImageRep))
    ##解像度
    set ocidNewImageSize to refMe's NSMakeSize(itemSize, itemSize)
(ocidSaveImageRep's setSize:ocidNewImageSize)
    ##保存
    set ocidNSInlineData to (ocidSaveImageRep's representationUsingType:(refMe's NSBitmapImageFileTypePNG) |properties|:(missing value))
    set boolDone to (ocidNSInlineData's writeToURL:(ocidSaveFilePathURL) atomically:true)
    
  end if
  
  
end repeat


delay 3
set strIconSetDirPath to ocidIconSaveDirPathURL's |path|() as text
set strIcnsFileName to ((ocidFileName as text) & ".icns") as text
set ocidSaveIcnsPathURL to (ocidIconSaveDirPathURL's URLByAppendingPathComponent:(strIcnsFileName))
set strIcnsFilePath to ocidSaveIcnsPathURL's |path|() as text
set strCommandText to ("/usr/bin/iconutil --convert icns \"" & strIconSetDirPath & "/\" -o \"" & strIcnsFilePath & "\"") as text
do shell script strCommandText




##出来上がったフォルダアイコンの場所を開く
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolDone to appSharedWorkspace's selectFile:(ocidIconSaveDirPathURL's |path|) inFileViewerRootedAtPath:(ocidIconSaveDirPathURL's |path|)

return "処理終了"


|

書類アイコンに画像を合成する

こんな感じのアイコンを生成します
Screen-5_20240212150301

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

#!/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 "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

####################################
#デフォルトの書類アイコンを取得しておく
####################################
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidPicturesDirPathURL to ocidURLsArray's firstObject()
set strSubPath to ("Icons/GenericDocumentIcon.iconset/") as text
set ocidSaveGenericFolderIconDirPathURL to (ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath))
set ocidSaveGenericFolderIconDirPath to ocidSaveGenericFolderIconDirPathURL's |path|
#
set boolDirExists to appFileManager's fileExistsAtPath:(ocidSaveGenericFolderIconDirPath) isDirectory:(true)
if boolDirExists = true then
log "アイコンイメージ書き出し済み"
else if boolDirExists = false then
log "アイコンイメージ書き出処理開始 1分ほどかかります"
  set boolDone to doMakeGenericDocumentIcon()
log "アイコンイメージ書き出終了"
end if
####################################
#合成するアイコンを選択する
####################################
###ダイアログ
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 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.image", "public.tiff", "public.jpeg", "public.png"}
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) as text
set ocidFilePath to refMe's NSString's stringWithString:(strFilePath)
set ocidImageFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath)
#


####################################
#ICONイメージを合成する
####################################
#保存先を作っておく
set strSubPath to ("Icons/DocumentIcon/") as text
set ocidSaveDirPathURL to ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath)
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
#
set numWidth to 512 as integer
set numHight to 512 as integer
##############################
#白アイコンを読み込み
set strSubPath to ("Icons/GenericDocumentIcon.iconset/icon_512x512.png") as text
set ocidReadIconFilePathURL to (ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath))
##
set ocidGenIconImage to (refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidReadIconFilePathURL))
set ocidGenIconImageRepArray to ocidGenIconImage's representations()
set ocidGenIconImageRep to (ocidGenIconImageRepArray's firstObject())
##############################
#合成するアイコンデータ読み込み
###CIイメージで読み込み
set ocidAddImageCI to (refMe's CIImage's imageWithContentsOfURL:(ocidImageFilePathURL) options:(missing value))
###ファイルのサイズを調べる
set ocidCGRect to ocidAddImageCI's extent()
####縦横の値を取得
set numImageWidth to refMe's CGRectGetWidth(ocidCGRect) as number
set numImageHeight to refMe's CGRectGetHeight(ocidCGRect) as number
if numImageWidth < numImageHeight then
  set numResizeScale to (256 / numImageHeight)
else
  ####リサイズする指数
  set numResizeScale to (256 / numImageWidth)
end if

####Transform指定
set recordCiImageData to (ocidAddImageCI's imageTransformForOrientation:(refMe's kCGImagePropertyOrientationUp))
####Transform適応
set ocidCiImageData to (ocidAddImageCI's imageByApplyingTransform:recordCiImageData)
####Parameters
set listParameters to {inputImage:ocidCiImageData, inputScale:numResizeScale, inputAspectRatio:1.0}
####リサイズする指数でリサイズ
set ocidCiFilterData to (refMe's CIFilter's filterWithName:"CILanczosScaleTransform" withInputParameters:listParameters)
#####リサイズ済みイメージ
set ocidResizedCiImage to ocidCiFilterData's outputImage()
#####NSBitmapImageRepに変換して
set ocidResizedImagePep to (refMe's NSBitmapImageRep's alloc()'s initWithCIImage:(ocidResizedCiImage))
set numResizedHigh to ocidResizedImagePep's pixelsHigh()
set numResizedWide to ocidResizedImagePep's pixelsWide()
if numImageWidth < numImageHeight then
  set numOffSetW to ((numResizedHigh - numResizedWide) / 2) as integer
  set numOffSetH to 0 as integer
else
  set numOffSetH to ((numResizedWide - numResizedHigh) / 2) as integer
  set numOffSetW to 0 as integer
end if

###########################################
###背景となる画像を作る
###########################################
set ocidSetColor to (refMe's NSColor's colorWithDeviceRed:0 green:0 blue:0 alpha:1)
set ocidBitmapFormat to refMe's NSBitmapFormatAlphaFirst
set ocidColorSpaceName to refMe's NSCalibratedRGBColorSpace
set ocidNSBitmapImageFileType to refMe's NSBitmapImageFileTypeTIFF
set ocidBitmapImageRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numWidth) pixelsHigh:(numHight) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(ocidColorSpaceName) bitmapFormat:(ocidBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
###初期化
refMe's NSGraphicsContext's saveGraphicsState()
(refMe's NSGraphicsContext's setCurrentContext:(refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:ocidBitmapImageRep))
####画像作成終了
refMe's NSGraphicsContext's restoreGraphicsState()

###########################################
###フォルダのイメージを重ねる
###########################################
refMe's NSGraphicsContext's saveGraphicsState()
###生成された画像でNSGraphicsContext初期化
set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidBitmapImageRep))
(refMe's NSGraphicsContext's setCurrentContext:(ocidContext))
set ocidFromRect to {origin:{x:0, y:0}, |size|:{width:512, Hight:512}}
set ocidDrawRect to {origin:{x:0, y:0}, |size|:{width:512, Hight:512}}
####フォルダ画像を背景画像上に配置する
set ocidOption to (refMe's NSCompositingOperationSourceOver)
log (ocidGenIconImageRep's drawInRect:(ocidDrawRect) fromRect:(ocidFromRect) operation:(ocidOption) fraction:1.0 respectFlipped:true hints:(missing value))
####画像作成終了
refMe's NSGraphicsContext's restoreGraphicsState()

###########################################
###ドロップシャドウ生成
###########################################
set ocidShadow to refMe's NSShadow's alloc()'s init()
set ocidShadowColor to (refMe's NSColor's colorWithDeviceRed:0 green:0 blue:0 alpha:0.5)
(ocidShadow's setShadowColor:(ocidShadowColor))
(ocidShadow's setShadowBlurRadius:(4))
set ocidShadowSize to refMe's NSMakeSize(3, -3)
(ocidShadow's setShadowOffset:(ocidShadowSize))
###########################################
###フォルダの上にアイコン画像を重ねる
###########################################
refMe's NSGraphicsContext's saveGraphicsState()
###生成された画像でNSGraphicsContext初期化
set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidBitmapImageRep))
(refMe's NSGraphicsContext's setCurrentContext:(ocidContext))
set ocidFromRect to {origin:{x:0, y:0}, |size|:{width:512, Hight:512}}
####
set numXoffSet to (128 + numOffSetW) as integer
set numYoffSet to (110 + numOffSetH) as integer
set ocidDrawRect to {origin:{x:(numXoffSet), y:(numYoffSet)}, |size|:{width:(256 * 2), Hight:(256 * 2)}}
###コマ画像を背景画像上に配置する
set ocidOption to (refMe's NSCompositingOperationSourceOver)
###ドロップシャドウ適応
ocidShadow's |set|()
log (ocidResizedImagePep's drawInRect:(ocidDrawRect) fromRect:(ocidFromRect) operation:(ocidOption) fraction:1.0 respectFlipped:true hints:(missing value))
####画像作成終了
refMe's NSGraphicsContext's restoreGraphicsState()

###########################################
###出力用にTIFFに変換する
###########################################
set ocidPropertyDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
####TIFF用の圧縮プロパティ(NSImageCompressionFactor)
(ocidPropertyDict's setObject:(refMe's NSNumber's numberWithBool:false) forKey:(refMe's NSImageInterlaced))
(ocidPropertyDict's setObject:(refMe's NSNumber's numberWithDouble:(1 / 2.2)) forKey:(refMe's NSImageGamma))

####インラインデータに変換
set ocidNSBitmapImageFileType to refMe's NSBitmapImageFileTypePNG
set ocidNSInlineData to (ocidBitmapImageRep's representationUsingType:(ocidNSBitmapImageFileType) |properties|:(ocidPropertyDict))
###########################################
###合成したアイコン画像はフォルダの中に
###########################################
set strDateNO to doGetDateNo("yyyyMMdd-HHmmss")
set strSaveFileName to (strDateNO & ".png") as text
set ocidSaveImagePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName))
###保存
set booleDone to (ocidNSInlineData's writeToURL:(ocidSaveImagePathURL) atomically:true)

##出来上がったフォルダアイコンの場所を開く
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolDone to appSharedWorkspace's selectFile:(ocidSaveDirPathURL's |path|) inFileViewerRootedAtPath:(ocidSaveDirPathURL's |path|)

return "処理終了"

####################################
#デフォルトの白書類アイコンデータを取得する
####################################
to doMakeGenericDocumentIcon()
  set appFileManager to refMe's NSFileManager's defaultManager()
  #パス
  set strIconFilePath to ("/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericDocumentIcon.icns") as text
  set ocidIconFilePath to refMe's NSString's stringWithString:(strIconFilePath)
  set ocidIconFilePathURL to refMe's NSURL's fileURLWithPath:(ocidIconFilePath)
  set ocidFileName to ocidIconFilePathURL's lastPathComponent()
  #フォルダを作っておく
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidPicturesDirPathURL to ocidURLsArray's firstObject()
  set strSubPath to ("Icons/GenericDocumentIcon.iconset") as text
  set ocidIconsDirPathURL to (ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath))
  set ocidSaveIconFilePathURL to ocidIconsDirPathURL's URLByAppendingPathComponent:(ocidFileName)
  set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
  # 777-->511 755-->493 700-->448 766-->502
(ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions))
  set listBoolMakeDir to (appFileManager's createDirectoryAtURL:(ocidIconsDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
  #コマンド整形
  set strIconFilePath to (ocidIconFilePathURL's |path|) as text
  set strSaveDirPath to (ocidIconsDirPathURL's |path|) as text
  try
    #コマンド実行
    set strCommandText to ("/usr/bin/iconutil --convert iconset \"" & strIconFilePath & "\" -o \"" & strSaveDirPath & "\"") as text
do shell script strCommandText
  end try
  #
  set listDone to appFileManager's copyItemAtURL:(ocidIconFilePathURL) toURL:(ocidSaveIconFilePathURL) |error|:(reference)
return (true as boolean)
  
end doMakeGenericDocumentIcon
#############################
### 今の日付日間 テキスト
##############################
to doGetDateNo(argDateFormat)
  ####日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  ###日付のフォーマットを定義
  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
  set ocidTimeZone to refMe's NSTimeZone's alloc()'s initWithName:"Asia/Tokyo"
ocidNSDateFormatter's setTimeZone:(ocidTimeZone)
ocidNSDateFormatter's setDateFormat:(argDateFormat)
  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo

|

[Icon]アプリケーションのアイコン付きのフォルダを作成する

こんな感じのアイコン作ります Screen-3_20240212123101

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

#!/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 "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidPicturesDirPathURL to ocidURLsArray's firstObject()
set strSubPath to ("Icons/GenericFolderIcon.iconset/") as text
set ocidSaveGenericFolderIconDirPathURL to (ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath))
set ocidSaveGenericFolderIconDirPath to ocidSaveGenericFolderIconDirPathURL's |path|
#
set boolDirExists to appFileManager's fileExistsAtPath:(ocidSaveGenericFolderIconDirPath) isDirectory:(true)
if boolDirExists = true then
log "アイコンイメージ書き出し済み"
else if boolDirExists = false then
log "アイコンイメージ書き出処理開始 1分ほどかかります"
doMakeGenericFolderIcon()
log "アイコンイメージ書き出終了"
end if


####################################
#アプリケーションのICONを取得する
####################################
###ダイアログ
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 NSApplicationDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidApplicationDirPathURL to ocidURLsArray's firstObject()
#ユーザーアプリケーションフォルダ無い人もいるので作っておく
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidApplicationDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
set aliasDefaultLocation to (ocidApplicationDirPathURL's absoluteURL()) as alias
#localizedを作っておく
set ocidNullStr to refMe's NSString's stringWithString:("")
set ocidLocalizedFilePathURL to (ocidApplicationDirPathURL's URLByAppendingPathComponent:(".localized"))
set listDone to ocidNullStr's writeToURL:(ocidLocalizedFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
#
try
  ## アプリケーション選択
  set listUTI to {"com.apple.application-bundle"}
  set strMes to ("アプリケーションを選択してください") as text
  set strPrompt to ("アプリケーションを選択してください") as text
  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles without multiple selections allowed and showing package contents) as alias
on error
log "エラーしました"
return "エラーしました"
end try

#パス
set strAppFilePath to (POSIX path of aliasFilePath) as text
set ocidAppFilePath to refMe's NSString's stringWithString:(strAppFilePath)
set ocidAppFilePathURL to refMe's NSURL's fileURLWithPath:(ocidAppFilePath)
#PLISTパス
set ocidPlistFilePathURL to ocidAppFilePathURL's URLByAppendingPathComponent:("Contents/Info.plist")
set listPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL) |error|:(reference)
set ocidPlistDict to (item 1 of listPlistDict)
if ocidPlistDict is (missing value) then
  #IOSアプリの場合
  set ocidPlistFilePathURL to ocidAppFilePathURL's URLByAppendingPathComponent:("WrappedBundle/Info.plist")
  set listPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL) |error|:(reference)
  set ocidPlistDict to (item 1 of listPlistDict)
end if
#バンドルIDで保存先iconsetフォルダ
set ocidBundleID to ocidPlistDict's valueForKey:("CFBundleIdentifier")
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidPicturesDirPathURL to ocidURLsArray's firstObject()
set strSubPath to ("Icons/AppIcon/" & ocidBundleID & ".iconset") as text
set ocidSaveAppIconsDirPathURL to ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath)
#
set ocidSaveAppIconsDirPath to ocidSaveAppIconsDirPathURL's |path|
#
set boolDirExists to appFileManager's fileExistsAtPath:(ocidSaveAppIconsDirPath) isDirectory:(true)
if boolDirExists = true then
log "アイコンイメージ書き出し済み"
else if boolDirExists = false then
log "アイコンイメージ書き出処理開始 1分ほどかかります"
  #フォルダがなければ作る
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
  # 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveAppIconsDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
doMakeAppFolderIconFile(ocidAppFilePathURL, ocidSaveAppIconsDirPathURL, ocidPlistDict)
log "アイコンイメージ書き出終了"
end if

####################################
#ICONイメージを合成する
####################################
#保存先を作っておく
set strSubPath to ("Icons/AppFolderIcon/" & ocidBundleID & "") as text
set ocidSaveDirPathURL to ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath)
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
#Classのリスト
set listFolderName to {"FolderDark", "SmartFolder", "Folder", "SmartFolderDark"} as list

repeat with itemFolderName in listFolderName
  ##OSのデフォルトフォルダイメージ読み込み
  set numWidth to 512 as integer
  set numHight to 512 as integer
  
  set strSubPath to ("Icons/GenericFolderIcon.iconset/" & itemFolderName & ".iconset/icon_512x512.png") as text
  set ocidReadIconFilePathURL to (ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath))
  ##
  set ocidGenIconImage to (refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidReadIconFilePathURL))
  set ocidGenIconImageRepArray to ocidGenIconImage's representations()
  set ocidGenIconImageRep to (ocidGenIconImageRepArray's firstObject())
  ##保存先確保
  set strSubPath to ("Icons/AppFolderIcon/" & ocidBundleID & "") as text
  set ocidSaveAppIconsDirPathURL to (ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath))
  ##
  set ocidWithIconDirPathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(itemFolderName))
  set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
  # 777-->511 755-->493 700-->448 766-->502
(ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions))
  set listBoolMakeDir to (appFileManager's createDirectoryAtURL:(ocidWithIconDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
  #合成するアイコンデータ読み込み
  set strSubPath to ("Icons/AppIcon/" & ocidBundleID & ".iconset/AppIcon.icns") as text
  set ocidAppIcnsFilePathURL to (ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath))
  ###CIイメージで読み込み
  set ocidAddImageCI to (refMe's CIImage's imageWithContentsOfURL:(ocidAppIcnsFilePathURL) options:(missing value))
  ###ファイルのサイズを調べる
  set ocidCGRect to ocidAddImageCI's extent()
  ####縦横の値を取得
  set numImageWidth to refMe's CGRectGetWidth(ocidCGRect) as number
  set numImageHeight to refMe's CGRectGetHeight(ocidCGRect) as number
  if numImageWidth < numImageHeight then
    set numResizeScale to (256 / numImageHeight)
  else
    ####リサイズする指数
    set numResizeScale to (256 / numImageWidth)
  end if
  
  ####Transform指定
  set recordCiImageData to (ocidAddImageCI's imageTransformForOrientation:(refMe's kCGImagePropertyOrientationUp))
  ####Transform適応
  set ocidCiImageData to (ocidAddImageCI's imageByApplyingTransform:recordCiImageData)
  ####Parameters
  set listParameters to {inputImage:ocidCiImageData, inputScale:numResizeScale, inputAspectRatio:1.0}
  ####リサイズする指数でリサイズ
  set ocidCiFilterData to (refMe's CIFilter's filterWithName:"CILanczosScaleTransform" withInputParameters:listParameters)
  #####リサイズ済みイメージ
  set ocidResizedCiImage to ocidCiFilterData's outputImage()
  #####NSBitmapImageRepに変換して
  set ocidResizedImagePep to (refMe's NSBitmapImageRep's alloc()'s initWithCIImage:(ocidResizedCiImage))
  set numResizedHigh to ocidResizedImagePep's pixelsHigh()
  set numResizedWide to ocidResizedImagePep's pixelsWide()
  if numImageWidth < numImageHeight then
    set numOffSetW to ((numResizedHigh - numResizedWide) / 2) as integer
    set numOffSetH to 0 as integer
  else
    set numOffSetH to ((numResizedWide - numResizedHigh) / 2) as integer
    set numOffSetW to 0 as integer
  end if
  
  ###########################################
  ###背景となる画像を作る
  ###########################################
  set ocidSetColor to (refMe's NSColor's colorWithDeviceRed:0 green:0 blue:0 alpha:1)
  set ocidBitmapFormat to refMe's NSBitmapFormatAlphaFirst
  set ocidColorSpaceName to refMe's NSCalibratedRGBColorSpace
  set ocidNSBitmapImageFileType to refMe's NSBitmapImageFileTypeTIFF
  set ocidBitmapImageRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numWidth) pixelsHigh:(numHight) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(ocidColorSpaceName) bitmapFormat:(ocidBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
  ###初期化
refMe's NSGraphicsContext's saveGraphicsState()
(refMe's NSGraphicsContext's setCurrentContext:(refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:ocidBitmapImageRep))
  ####画像作成終了
refMe's NSGraphicsContext's restoreGraphicsState()
  
  ###########################################
  ###フォルダのイメージを重ねる
  ###########################################
refMe's NSGraphicsContext's saveGraphicsState()
  ###生成された画像でNSGraphicsContext初期化
  set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidBitmapImageRep))
(refMe's NSGraphicsContext's setCurrentContext:(ocidContext))
  set ocidFromRect to {origin:{x:0, y:0}, |size|:{width:512, Hight:512}}
  set ocidDrawRect to {origin:{x:0, y:0}, |size|:{width:512, Hight:512}}
  ####フォルダ画像を背景画像上に配置する
  set ocidOption to (refMe's NSCompositingOperationSourceOver)
log (ocidGenIconImageRep's drawInRect:(ocidDrawRect) fromRect:(ocidFromRect) operation:(ocidOption) fraction:1.0 respectFlipped:true hints:(missing value))
  ####画像作成終了
refMe's NSGraphicsContext's restoreGraphicsState()
  
  ###########################################
  ###ドロップシャドウ生成
  ###########################################
  set ocidShadow to refMe's NSShadow's alloc()'s init()
  set ocidShadowColor to (refMe's NSColor's colorWithDeviceRed:0 green:0 blue:0 alpha:0.5)
(ocidShadow's setShadowColor:(ocidShadowColor))
(ocidShadow's setShadowBlurRadius:(4))
  set ocidShadowSize to refMe's NSMakeSize(3, -3)
(ocidShadow's setShadowOffset:(ocidShadowSize))
  ###########################################
  ###フォルダの上にアイコン画像を重ねる
  ###########################################
refMe's NSGraphicsContext's saveGraphicsState()
  ###生成された画像でNSGraphicsContext初期化
  set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidBitmapImageRep))
(refMe's NSGraphicsContext's setCurrentContext:(ocidContext))
  set ocidFromRect to {origin:{x:0, y:0}, |size|:{width:512, Hight:512}}
  ####
  set numXoffSet to (128 + numOffSetW) as integer
  set numYoffSet to (110 + numOffSetH) as integer
  set ocidDrawRect to {origin:{x:(numXoffSet), y:(numYoffSet)}, |size|:{width:(256 * 2), Hight:(256 * 2)}}
  ###コマ画像を背景画像上に配置する
  set ocidOption to (refMe's NSCompositingOperationSourceOver)
  ###ドロップシャドウ適応
ocidShadow's |set|()
log (ocidResizedImagePep's drawInRect:(ocidDrawRect) fromRect:(ocidFromRect) operation:(ocidOption) fraction:1.0 respectFlipped:true hints:(missing value))
  ####画像作成終了
refMe's NSGraphicsContext's restoreGraphicsState()
  
  ###########################################
  ###出力用にTIFFに変換する
  ###########################################
  set ocidNSBitmapImageRepPropertyKey to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
  ####TIFF用の圧縮プロパティ(NSImageCompressionFactor)
(ocidNSBitmapImageRepPropertyKey's setObject:0 forKey:(refMe's NSImageCompressionFactor))
  ####インラインデータに変換
  set ocidNSBitmapImageFileType to refMe's NSBitmapImageFileTypeTIFF
  set ocidNSInlineData to (ocidBitmapImageRep's representationUsingType:(ocidNSBitmapImageFileType) |properties|:(ocidNSBitmapImageRepPropertyKey))
  ###########################################
  ###合成したアイコン画像はフォルダの中に
  ###########################################
  set strTiffFileName to ((itemFolderName as text) & ".tiff") as text
  set ocidSaveImagePathURL to (ocidWithIconDirPathURL's URLByAppendingPathComponent:(strTiffFileName))
  ###保存
  set booleDone to (ocidNSInlineData's writeToURL:(ocidSaveImagePathURL) atomically:true)
  
  ###########################################
  ###フォルダにアイコンを付与する
  ###########################################
  ##NSIMAGEにして
  set ocidAddIconImageSize to ocidBitmapImageRep's |size|()
  set ocidAddIconImageData to (refMe's NSImage's alloc()'s initWithSize:(ocidAddIconImageSize))
(ocidAddIconImageData's addRepresentation:(ocidBitmapImageRep))
  ###フォルダにアイコン付与
  set ocidAddIconDirPath to ocidWithIconDirPathURL's |path|
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  set booleDone to (appSharedWorkspace's setIcon:(ocidAddIconImageData) forFile:(ocidAddIconDirPath) options:(refMe's NSExclude10_4ElementsIconCreationOption))
  
end repeat
##出来上がったフォルダアイコンの場所を開く
set ocidContainerIconDirPathURL to ocidWithIconDirPathURL's URLByDeletingLastPathComponent()
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolDone to appSharedWorkspace's selectFile:(ocidContainerIconDirPathURL's |path|) inFileViewerRootedAtPath:(ocidContainerIconDirPathURL's |path|)

return "処理終了"



####################################
#Assets.carからicnsファイル
####################################
to doExtractAssets(argAppFilePathURL, argIconsSaveDirPathURL)
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidFilePathURL to argAppFilePathURL's URLByAppendingPathComponent:("Contents/Resources/Assets.car") isDirectory:false
  set ocidFilePath to ocidFilePathURL's |path|
  set boolExists to appFileManager's fileExistsAtPath:(ocidFilePath)
  if boolExists is false then
    set ocidFilePathURL to argAppFilePathURL's URLByAppendingPathComponent:("WrappedBundle/Assets.car") isDirectory:false
    set ocidFilePath to ocidFilePathURL's |path|
    set boolExists to appFileManager's fileExistsAtPath:(ocidFilePath)
    if boolExists is false then
return "Assets.carが見つかりません"
    end if
  end if
  set strFilePath to ocidFilePath as text
  set strSaveDirPath to (argIconsSaveDirPathURL's |path|) as text
  try
    ###AppIcon指定時
    set strCommandText to ("/usr/bin/iconutil --convert iconset \"" & strFilePath & "\" AppIcon -o \"" & strSaveDirPath & "\"") as text
do shell script strCommandText
  on error
    ###システム設定の指定例
    set strCommandText to ("/usr/bin/iconutil --convert iconset \"" & strFilePath & "\" PrefApp -o \"" & strSaveDirPath & "\"") as text
do shell script strCommandText
  end try
  set ocidSaveIconFilePathURL to argIconsSaveDirPathURL's URLByAppendingPathComponent:("AppIcon.icns") isDirectory:false
  set strSaveIconFilePath to (ocidSaveIconFilePathURL's |path|) as text
  try
    set strCommandText to ("/usr/bin/iconutil --convert icns \"" & strSaveDirPath & "\" -o \"" & strSaveIconFilePath & "\" ") as text
do shell script strCommandText
  end try
end doExtractAssets


####################################
#Assets.car からiconsetを書き出す
####################################
to doMakeGenericFolderIcon()
  set appFileManager to refMe's NSFileManager's defaultManager()
  #パス
  set strCarFilePath to ("/System/Library/PrivateFrameworks/IconFoundation.framework/Versions/A/Resources/Assets.car") as text
  set ocidCarFilePath to refMe's NSString's stringWithString:(strCarFilePath)
  set ocidCarFilePathURL to refMe's NSURL's fileURLWithPath:(ocidCarFilePath)
  set ocidFileName to ocidCarFilePathURL's lastPathComponent()
  #Classのリスト
  set listFolderName to {"FolderDark", "SmartFolder", "Folder", "SmartFolderDark"} as list
  #
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidPicturesDirPathURL to ocidURLsArray's firstObject()
  #Classの数だけ繰り返し
  repeat with itemFolderName in listFolderName
    set strSubPath to ("Icons/GenericFolderIcon.iconset/" & itemFolderName & ".iconset") as text
    set ocidIconsDirPathURL to (ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath))
    set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
    # 777-->511 755-->493 700-->448 766-->502
(ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions))
    set listBoolMakeDir to (appFileManager's createDirectoryAtURL:(ocidIconsDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
    ############
    #コマンド整形
    set strIconFilePath to (ocidCarFilePathURL's |path|) as text
    set strSaveDirPath to (ocidIconsDirPathURL's |path|) as text
    try
      #コマンド実行
      set strCommandText to ("/usr/bin/iconutil --convert iconset \"" & strIconFilePath & "\" " & itemFolderName & " -o \"" & strSaveDirPath & "\"") as text
do shell script strCommandText
    end try
  end repeat
  #
  set strSubPath to ("Icons/GenericFolderIcon.iconset") as text
  set ocidIconsDirPathURL to ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath)
  set ocidDistIconFilePathURL to ocidIconsDirPathURL's URLByAppendingPathComponent:("AppIcon.icns")
  set listDone to appFileManager's copyItemAtURL:(ocidCarFilePathURL) toURL:(ocidDistIconFilePathURL) |error|:(reference)
  #Classのリスト
  set listFolderName to {"FolderDark", "SmartFolder", "Folder", "SmartFolderDark"} as list
  #Classの数だけ繰り返し
  repeat with itemFolderName in listFolderName
    set strSubPath to ("Icons/GenericFolderIcon.iconset/" & itemFolderName & ".iconset") as text
    set ocidIconsDirPathURL to (ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath))
    set strFileNamePath to ("Icons/GenericFolderIcon.iconset/" & itemFolderName & ".icns") as text
    set ocidSaveFilePathURL to (ocidPicturesDirPathURL's URLByAppendingPathComponent:(strFileNamePath))
    ############
    set strIconDirPath to (ocidIconsDirPathURL's |path|) as text
    set strSaveFilePath to (ocidSaveFilePathURL's |path|) as text
    try
      set strCommandText to ("/usr/bin/iconutil --convert icns \"" & strIconDirPath & "\" -o \"" & strSaveFilePath & "\"") as text
do shell script strCommandText
    end try
  end repeat
  
  
end doMakeGenericFolderIcon

####################################
#アプリケーションのアイコンを取得
####################################
to doMakeAppFolderIconFile(argAppFilePathURL, argSaveAppIconsDirPathURL, argPlistDict)
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidPlistDict to argPlistDict
  set ocidAppFilePathURL to argAppFilePathURL
  set ocidSaveAppIconsDirPathURL to argSaveAppIconsDirPathURL
  set ocidIconFileName to ocidPlistDict's valueForKey:("CFBundleIconFile")
  #Iconファイルの指定がない場合
  if ocidIconFileName = (missing value) then
    #サブルーチンを実行してAssets.carからicnsファイルを生成する
doExtractAssets(ocidAppFilePathURL, ocidSaveAppIconsDirPathURL)
log "Icnsファイルの指定がありあません"
  end if
  #Iconファイルの指定がある場合
  set boolIcns to (ocidIconFileName's hasSuffix:("icns")) as boolean
  set strSubPath to ("Contents/Resources/" & ocidIconFileName) as text
  if boolIcns is true then
    #拡張子まで指定されている場合
    set ocidIconFilePathURL to ocidAppFilePathURL's URLByAppendingPathComponent:(strSubPath)
  else
    #拡張子指定がない場合は拡張子をつけておく
    set ocidIconFilePathURL to ocidAppFilePathURL's URLByAppendingPathComponent:(strSubPath)
    set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:("icns")
  end if
  set ocidIconFileName to ocidIconFilePathURL's lastPathComponent()
  #iconsetにイメージファイルを書き出して
  set strIconFilePath to (ocidIconFilePathURL's |path|) as text
  set strSaveDirPath to (ocidSaveAppIconsDirPathURL's |path|) as text
  try
    set strCommandText to ("/usr/bin/iconutil --convert iconset \"" & strIconFilePath & "\" -o \"" & strSaveDirPath & "\"") as text
do shell script strCommandText
  end try
  #Icnsファイルは普通にコピーする
  set ocidDistIconFilePathURL to ocidSaveAppIconsDirPathURL's URLByAppendingPathComponent:("AppIcon.icns")
  set listDone to appFileManager's copyItemAtURL:(ocidIconFilePathURL) toURL:(ocidDistIconFilePathURL) |error|:(reference)
return
end doMakeAppFolderIconFile


|

[NSPredicate]fluentuiのアイコン検索フォルダ名で検索(簡易検索)

自分でも何作っているのか?わからん

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

#!/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.6"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions
property refMe : a reference to current application

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



tell application "Finder"
  set aliasPathToMe to (path to me) as alias
  set aliasContainerDirPath to (container of aliasPathToMe) as alias
end tell
##
set strDirPath to (POSIX path of aliasContainerDirPath) as text
set ocidDirPathStr to refMe's NSString's stringWithString:(strDirPath)
set ocidDirPath to ocidDirPathStr's stringByStandardizingPath()
set ocidDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidDirPath) isDirectory:true)
########################
# SVGアセットの有無
########################
set ocidAssetsDirPathURL to ocidDirPathURL's URLByAppendingPathComponent:("Assets")
set ocidAssetsDirPath to ocidAssetsDirPathURL's |path|()
set boolDirExists to appFileManager's fileExistsAtPath:(ocidAssetsDirPath) isDirectory:(true)
if boolDirExists = true then
log "アセットがあるので継続します"
else if boolDirExists = false then
log "アセットが無いのでダウンロードします"
  set strGitBaseURL to ("https://codeload.github.com/microsoft/fluentui-system-icons/zip/refs/heads/main") as text
  set ocidTempDirURL to appFileManager's temporaryDirectory()
  set ocidUUID to refMe's NSUUID's alloc()'s init()
  set ocidUUIDString to ocidUUID's UUIDString
  set ocidTmpDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidTmpDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  set strFileName to "main.zip" as text
  set ocidZipFilePathURL to ocidTmpDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
  set strZipFilePath to ocidZipFilePathURL's |path|() as text
log "ダウンロード開始"
  set strCommandText to ("/usr/bin/curl " & strGitBaseURL & " -o \"" & strZipFilePath & "\"") as text
do shell script strCommandText
log "ダウンロードしたファイルを解凍します"
  set strTmpDirPathURL to ocidTmpDirPathURL's |path| as text
  set strCommandText to ("/usr/bin/unzip \"" & strZipFilePath & "\" -d \"" & strTmpDirPathURL & "\"") as text
do shell script strCommandText
log "解凍したファイルを移動します"
  set strExtPath to (strTmpDirPathURL & "/fluentui-system-icons-main/ios/FluentIcons/Assets/IconAssets.xcassets") as text
  set strAssetsDirPath to ocidAssetsDirPath as text
  set strCommandText to ("bin/mv \"" & strExtPath & "\" \"" & strAssetsDirPath & "\"") as text
do shell script strCommandText
end if
########################
# 検索用のインデクスの有無
########################
set ocidIndexDirPathURL to ocidDirPathURL's URLByAppendingPathComponent:("AssetsIndex")
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidIndexDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
#検索結果保存用のディレクトリ
set ocidResultDirPathURL to ocidDirPathURL's URLByAppendingPathComponent:("Result")
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidResultDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
#検索用のファイル
set ocidPlistFilePathURL to ocidIndexDirPathURL's URLByAppendingPathComponent:("index.plist")
set ocidJsonFilePathURL to ocidIndexDirPathURL's URLByAppendingPathComponent:("index.json")
set ocidPlistFilePath to ocidPlistFilePathURL's |path|()
# ファイルの有無チェック
set boolFileExists to appFileManager's fileExistsAtPath:(ocidPlistFilePath) isDirectory:(false)
if boolFileExists = true then
log "検索用ファイルがすでにある"
  set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL)
  set ocidJsonArray to ocidPlistDict's objectForKey:("filename-array")
else if boolFileExists = false then
log "検索用ファイルが無いので作成します"
  set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
  set ocidKeyArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
ocidKeyArray's addObject:(refMe's NSURLPathKey)
ocidKeyArray's addObject:(refMe's NSURLIsDirectoryKey)
ocidKeyArray's addObject:(refMe's NSURLNameKey)
  #Assetsディレクトリの第一階層のフォルダ名を取得する
  set listContents to appFileManager's contentsOfDirectoryAtURL:(ocidAssetsDirPathURL) includingPropertiesForKeys:(ocidKeyArray) options:(ocidOption) |error|:(reference)
  set ocidContentsURLArray to (item 1 of listContents)
  #取得したフォルダ名NSURLをA-Z順に並び替え
  set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("absoluteString") ascending:(yes) selector:"localizedStandardCompare:"
  set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidDescriptor)
  set ocidSortedArray to ocidContentsURLArray's sortedArrayUsingDescriptors:(ocidDescriptorArray)
  #保存用
  set ocidJsonArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
  set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
  #並び替えたパスを順番に処理
  repeat with itemURL in ocidSortedArray
    ##フォルダ名を取得して
    set listValue to (itemURL's getResourceValue:(reference) forKey:(refMe's NSURLNameKey) |error|:(reference))
    set ocidDirName to (item 2 of listValue)
    #拡張子を削除してから
    set ocidBaseFileName to ocidDirName's stringByDeletingPathExtension()
    ## set ocidFileName to (ocidBaseFileName's stringByAppendingPathExtension:("svg"))
    #保存用のデータに格納
(ocidJsonArray's addObject:(ocidBaseFileName))
  end repeat
  #JSON用に収集したデータをPLIST用のデータに格納
ocidPlistDict's setObject:(ocidJsonArray) forKey:("filename-array")
  ######
  #PLITで保存
  set ocidFormat to (refMe's NSPropertyListBinaryFormat_v1_0)
  set listPlistData to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFormat) options:0 |error|:(reference)
  set ocidPlistData to (item 1 of listPlistData)
  set listDone to ocidPlistData's writeToURL:(ocidPlistFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference)
  #####
  #JSONで保存
  set listJSONSerialization to (refMe's NSJSONSerialization's dataWithJSONObject:(ocidJsonArray) options:(refMe's NSJSONWritingPrettyPrinted) |error|:(reference))
  set ocidJsonData to (item 1 of listJSONSerialization)
  set ocidJsonStr to refMe's NSString's alloc()'s initWithData:(ocidJsonData) encoding:(refMe's NSUTF8StringEncoding)
  set listDone to ocidJsonStr's writeToURL:(ocidJsonFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
end if



########################
## クリップボードの中身取り出し
###初期化
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to appPasteboard's types
###テキストがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###値を格納する
  tell application "Finder"
    set strReadString to (the clipboard as text) as text
  end tell
  ###Finderでエラーしたら
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strReadString to ocidReadString as text
  else
log "テキストなし"
    set strReadString to "半角英数で検索文字列を入力してください" as text
  end if
end if

###ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set aliasIconPath to (POSIX file "/System/Library/CoreServices/Tips.app/Contents/Resources/AppIcon.icns") as alias
set strTitle to ("入力してください") as text
set strMes to ("半角英数で検索文字入力") as text
set recordResult to (display dialog strMes with title strTitle default answer strReadString buttons {"キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 30 with icon aliasIconPath without hidden answer)

if (gave up of recordResult) is true then
return "時間切れです"
else if (button returned of recordResult) is "キャンセル" then
return "キャンセルです"
else
  set strReturnedText to (text returned of recordResult) as text
end if
##############################
###戻り値整形
set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedText))
###タブと改行を除去しておく
set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidTextM's appendString:(ocidResponseText)
##改行除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
##タブ除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
##英数の小文字にする
set ocidPredicateText to ocidTextM's lowercaseString()
set strPredicateText to ("SELF CONTAINS[c] '" & ocidPredicateText & "'") as text
##############################
### 検索
set ocidPredicate to refMe's NSPredicate's predicateWithFormat:(strPredicateText)
set ocidSearchAns to ocidJsonArray's filteredArrayUsingPredicate:(ocidPredicate)
##検索結果をソート
set ocidAnsSortedArray to ocidSearchAns's sortedArrayUsingSelector:("caseInsensitiveCompare:")

##############################
set strPredicateText to ocidPredicateText as text
###パス
set strFileName to (strPredicateText & ".html") as text
set ocidSaveFilePathURL to ocidResultDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false

##############################
# XML 生成開始
##############################
#XML初期化
set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init()
ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentHTMLKind)
# DTD付与
set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
ocidDTD's setName:("html")
ocidXMLDoc's setDTD:(ocidDTD)
# XML主要部分を生成
set strTitleText to ("【fluent】: " & ocidPredicateText & " :検索結果") as text
set ocidRootElement to doMakeRootElement(strTitleText)
#ボディエレメント
set ocidBodyElement to refMe's NSXMLElement's elementWithName:("body")
#ヘッダー
set ocidHeaderElement to refMe's NSXMLElement's elementWithName:("header")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("header")
ocidHeaderElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_header")
ocidHeaderElement's addAttribute:(ocidAddNode)
ocidBodyElement's addChild:(ocidHeaderElement)
#アーティクル
set ocidArticleElement to refMe's NSXMLElement's elementWithName:("article")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("article")
ocidArticleElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_article")
ocidArticleElement's addAttribute:(ocidAddNode)
ocidBodyElement's addChild:(ocidArticleElement)
#フッター
set ocidFooterElement to refMe's NSXMLElement's elementWithName:("footer")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("footer")
ocidFooterElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_footer")
ocidFooterElement's addAttribute:(ocidAddNode)
#リンク付与(不要なら削除可)
set ocidAElement to refMe's NSXMLElement's elementWithName:("a")
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:("https://quicktimer.cocolog-nifty.com/"))
(ocidAElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
(ocidAElement's addAttribute:(ocidAddNode))
set strContents to ("AppleScriptで生成しました") as text
(ocidAElement's setStringValue:(strContents))
ocidFooterElement's addChild:(ocidAElement)
ocidBodyElement's addChild:(ocidFooterElement)
##############################
# TABLE コンテンツ部分生成開始
##############################
#テーブル部生成開始
set ocidTableElement to refMe's NSXMLElement's elementWithName:("table")
###【caption】
set ocidCaptionElement to refMe's NSXMLElement's elementWithName:("caption")
ocidCaptionElement's setStringValue:(strTitleText)
ocidTableElement's addChild:(ocidCaptionElement)
###【colgroup】
set ocidColgroupElement to refMe's NSXMLElement's elementWithName:("colgroup")
#テーブルのタイトル部
set listColName to {"行番号", "イメージ", "ファイル名", "リンク"} as list
#タイトル部の数だけ繰り返し
repeat with itemColName in listColName
  ###【col】col生成
  set ocidAddElement to (refMe's NSXMLElement's elementWithName:("col"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName))
(ocidAddElement's addAttribute:(ocidAddNode))
(ocidColgroupElement's addChild:(ocidAddElement))
end repeat
#テーブルエレメントに追加
ocidTableElement's addChild:(ocidColgroupElement)
###【thead】
set ocidTheadElement to refMe's NSXMLElement's elementWithName:("thead")
#TR
set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr")
#タイトル部の数だけ繰り返し
repeat with itemColName in listColName
  #ここはTDではなくてTHを利用
  set ocidAddElement to (refMe's NSXMLElement's elementWithName:("th"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName))
(ocidAddElement's addAttribute:(ocidAddNode))
  #値を入れる
(ocidAddElement's setStringValue:(itemColName))
  #TH→TRにセット
(ocidTrElement's addChild:(ocidAddElement))
end repeat
#TRをTHEADにセット
ocidTheadElement's addChild:(ocidTrElement)
#THEADをテーブルにセット
ocidTableElement's addChild:(ocidTheadElement)
################################################
###【tbody】
set ocidTbodyElement to refMe's NSXMLElement's elementWithName:("tbody")
#行番号
set numCntLineNo to 1 as integer
#ファイルのパスの数だけ繰り返し
repeat with itemKeyName in ocidAnsSortedArray
  #TRの開始
  set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr"))
  #【行番号】をTHでセット
  set strZeroSupp to ("00") as text
  set strZeroSupp to ("00" & numCntLineNo) as text
  set strLineNO to (text -3 through -1 of strZeroSupp) as text
  set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("行番号"))
(ocidThElement's addAttribute:(ocidAddNode))
(ocidThElement's setStringValue:(strLineNO))
(ocidTrElement's addChild:(ocidThElement))
  #【項目名=KEY名】をTDでセット
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("イメージ"))
  #SVGファイルへのイメージリンク
  set ocidBaseSubDirPathURL to (ocidAssetsDirPathURL's URLByAppendingPathComponent:(itemKeyName))
  set ocidSubDirPathURL to (ocidBaseSubDirPathURL's URLByAppendingPathExtension:("imageset"))
  set strSubDirPathURL to ocidSubDirPathURL's absoluteString() as text
  set ocidBaseSvgFilePathURL to (ocidSubDirPathURL's URLByAppendingPathComponent:(itemKeyName))
  set ocidSvgFilePathURL to (ocidBaseSvgFilePathURL's URLByAppendingPathExtension:("svg"))
  set strSvgFilePath to ocidSvgFilePathURL's absoluteString() as text
  #SVGアイコンをクリックでファイルを開くようにaタグ
  set ocidSvgImageAElement to (refMe's NSXMLElement's elementWithName:("a"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(strSvgFilePath))
(ocidSvgImageAElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
(ocidSvgImageAElement's addAttribute:(ocidAddNode))
  #SVGファイルはimgタグで配置
  set ocidSvgImageImgElement to (refMe's NSXMLElement's elementWithName:("img"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("src") stringValue:(strSvgFilePath))
(ocidSvgImageImgElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("alt") stringValue:(itemKeyName))
(ocidSvgImageImgElement's addAttribute:(ocidAddNode))
(ocidSvgImageAElement's addChild:(ocidSvgImageImgElement))
(ocidTdElement's addChild:(ocidSvgImageAElement))
  #TDをTRにセット
(ocidTrElement's addChild:(ocidTdElement))
  #######【ファイル名】TD
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("ファイル名"))
  set strKeyName to itemKeyName as text
  set strSetValue to (strKeyName & ".svg")
(ocidTdElement's setStringValue:(strSetValue))
(ocidTdElement's addAttribute:(ocidAddNode))
  #TDをTRにセット
(ocidTrElement's addChild:(ocidTdElement))
  #######【リンク】
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("リンク"))
(ocidTdElement's addAttribute:(ocidAddNode))
  #ファイルへのリンクをディレクトリにリンクにした(Safariで便利だから)
  set ocidSvgLinkElement to (refMe's NSXMLElement's elementWithName:("a"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(strSubDirPathURL))
(ocidSvgLinkElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
(ocidSvgLinkElement's addAttribute:(ocidAddNode))
(ocidSvgLinkElement's setStringValue:(strSetValue))
(ocidTdElement's addChild:(ocidSvgLinkElement))
  #TDをTRにセット
(ocidTrElement's addChild:(ocidTdElement))
  #出来上がったTRをTBODYにセット
(ocidTbodyElement's addChild:(ocidTrElement))
  #
  set numCntLineNo to (numCntLineNo + 1) as integer
end repeat
#TBODYをテーブルにセット
ocidTableElement's addChild:(ocidTbodyElement)
################################################
###【tfoot】 TRで
set ocidTfootElement to refMe's NSXMLElement's elementWithName:("tfoot")
set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr")
#項目数を取得して
set numCntCol to (count of listColName) as integer
#colspan指定して1行でセット
set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("テーブルの終わり"))
(ocidThElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("colspan") stringValue:(numCntCol as text))
(ocidThElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("row"))
(ocidThElement's addAttribute:(ocidAddNode))
#項目キーの数
set numCntKey to (count of ocidAnsSortedArray) as integer
set strValue to ("メタデータの数は:" & numCntKey & " 件でした") as text
ocidThElement's setStringValue:(strValue)
#THをTRにセットして
ocidTrElement's addChild:(ocidThElement)
#TRをTFOOTにセット
ocidTfootElement's addChild:(ocidTrElement)
#TFOOTをテーブルにセット
ocidTableElement's addChild:(ocidTfootElement)
# 出来上がったテーブルをArticleエレメントにセット
ocidArticleElement's addChild:(ocidTableElement)
#ルートエレメントにセット
ocidRootElement's addChild:(ocidBodyElement)
##############################
# TABLE
##############################
#ROOTエレメントをXMLにセット
ocidXMLDoc's setRootElement:(ocidRootElement)
#読み取りやすい表示
set ocidXMLdata to ocidXMLDoc's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint)
#保存
set listDone to ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference)

##############################
#開く
##############################
####サファリで開く
set strOpenURL to ocidSaveFilePathURL's absoluteString() as text
tell application "Safari"
activate
make new document with properties {name:"SEARCH2HTMLV3"}
  tell window 1
open location strOpenURL
  end tell
end tell


return
##############################
# 基本的なHTMLの構造
##############################
to doMakeRootElement(argStrTitleText)
  set strTitleText to argStrTitleText as text
  #
  set ocidRootElement to refMe's NSXMLElement's elementWithName:("html")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("lang") stringValue:("ja")
ocidRootElement's addAttribute:(ocidAddNode)
  #
  set ocidHeadElement to refMe's NSXMLElement's elementWithName:("head")
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("title")
ocidAddElement's setStringValue:(strTitleText)
ocidHeadElement's addChild:(ocidAddElement)
  # http-equiv
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Type")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/html; charset=UTF-8")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Style-Type")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/css")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Script-Type")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/javascript")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=720")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("style")
ocidAddElement's setStringValue:("body { margin: 10px; background-color: #FFFFFF; } table { border-spacing: 0; caption-side: top; font-family: system-ui; } thead th { border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; &:first-of-type { border-start-start-radius: .5em } &:last-of-type { border-start-end-radius: .5em; border-inline-end-width: 1px } } tbody td { word-wrap: break-word;max-width: 360px;border-spacing: 0; border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; &:last-of-type { border-inline-end-width: 1px } } tbody th { border-spacing: 0; border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; } tbody tr:nth-of-type(odd) { background: #F2F2F2; } .kind_string { font-size: 0.75em; } .date_string { font-size: 0.5em; } tfoot th { border: solid 1px #666666; padding: .5ch 1ch; &:first-of-type { border-end-start-radius: .5em } &:last-of-type { border-end-end-radius: .5em; border-inline-end-width: 1px } }")
ocidHeadElement's addChild:(ocidAddElement)
  #
ocidRootElement's addChild:(ocidHeadElement)
  #
return ocidRootElement
end doMakeRootElement



|

Osデフォルトのアイコンを書き出す

Screen20230925103430

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

#!/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 "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

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

############
set strCarFilePath to ("/System/Library/PrivateFrameworks/IconFoundation.framework/Versions/A/Resources/Assets.car") as text
set ocidCarFilePath to refMe's NSString's stringWithString:(strCarFilePath)
set ocidCarFilePathURL to refMe's NSURL's fileURLWithPath:(ocidCarFilePath)
set ocidFileName to ocidCarFilePathURL's lastPathComponent()


set listFolderName to {"FolderDark", "SmartFolder", "Folder", "SmartFolderDark"} as list

repeat with itemFolderName in listFolderName
  ############
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidPicturesDirPathURL to ocidURLsArray's firstObject()
  set strSubPath to ("Icons/GenericFolderIcon.iconset/" & itemFolderName & ".iconset") as text
  set ocidIconsDirPathURL to (ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath))
  set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
  # 777-->511 755-->493 700-->448 766-->502
(ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions))
  set listBoolMakeDir to (appFileManager's createDirectoryAtURL:(ocidIconsDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
  ############
  set strIconFilePath to (ocidCarFilePathURL's |path|) as text
  set strSaveDirPath to (ocidIconsDirPathURL's |path|) as text
  try
    set strCommandText to ("/usr/bin/iconutil --convert iconset \"" & strIconFilePath & "\" " & itemFolderName & " -o \"" & strSaveDirPath & "\"") as text
do shell script strCommandText
  end try
end repeat
############
set strSubPath to ("Icons/GenericFolderIcon.iconset") as text
set ocidIconsDirPathURL to ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath)
set ocidDistIconFilePathURL to ocidIconsDirPathURL's URLByAppendingPathComponent:(ocidFileName)
set listDone to appFileManager's copyItemAtURL:(ocidCarFilePathURL) toURL:(ocidDistIconFilePathURL) |error|:(reference)

set listFolderName to {"FolderDark", "SmartFolder", "Folder", "SmartFolderDark"} as list

repeat with itemFolderName in listFolderName
  set strSubPath to ("Icons/GenericFolderIcon.iconset/" & itemFolderName & ".iconset") as text
  set ocidIconsDirPathURL to (ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath))
  set strFileNamePath to ("Icons/GenericFolderIcon.iconset/" & itemFolderName & ".icns") as text
  set ocidSaveFilePathURL to (ocidPicturesDirPathURL's URLByAppendingPathComponent:(strFileNamePath))
  ############
  set strIconDirPath to (ocidIconsDirPathURL's |path|) as text
  set strSaveFilePath to (ocidSaveFilePathURL's |path|) as text
  try
    set strCommandText to ("/usr/bin/iconutil --convert icns \"" & strIconDirPath & "\" -o \"" & strSaveFilePath & "\"") as text
do shell script strCommandText
  end try
  
end repeat


############
set ocidSelectFilePath to ocidDistIconFilePathURL's |path|
set ocidContainerDirPath to ocidIconsDirPathURL's |path|
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolDone to appSharedWorkspace's selectFile:(ocidSelectFilePath) inFileViewerRootedAtPath:(ocidContainerDirPath)



return "処理終了"





|

iconutil

Icon画像のコンバートを行う

A:入力
icns car ファイル
iconset 画像が格納されているディレクトリ

B:出力
icns Apple Icon画像ファイル

iconsetディレクトリを指定

重要
iconset指定はディレクトリ指定 XXXXXXX.iconset のようにiconsetが必須

アプリケーションのアイコンを書き出す
https://quicktimer.cocolog-nifty.com/icefloe/2023/12/post-31c6d3.html
[Icon]GenericFolderIconV3
https://quicktimer.cocolog-nifty.com/icefloe/2023/08/post-f55deb.html


iconutil(1) General Commands Manual iconutil(1)

NAME
iconutil  Utility to convert between '.iconset' and '.icns' files.

SYNOPSIS
iconutil -c {icns | iconset} [-o file] file [icon-name]

DESCRIPTION
iconutil converts between '.iconset' and '.icns' files, and can extract
icons from '.car' asset catalog files. The tool takes a single source
     '.icns' file, '.iconset' or a '.car' file and icon name. It converts the
input to either a '.icns' or '.iconset' depending on the value of the -c
flag's argument. It is possible to specify the name of the output file by
passing the file path as the argument to the -o flag. If -o is not set
iconutil will write converted '.icns' file or '.iconset' to the same
directory as the source file using either the name of the icon in the
'.car' or the input file name with the extension derived from the output
type.

OPTIONS
-c --convert {icns | iconset}
Given the argument iconset, iconutil converts the source '.icns'
file to an '.iconset'. The '.iconset' is saved in the same
directory as the source '.icns'. It is given a file name derived
from the input file name or the input icon name with the
'.iconset' file extension. If the argument is icns, iconutil
converts the source '.iconset' to an '.icns'. The '.icns' is
saved in the same directory as the source '.iconset'. It is given
a file name derived from the input file name or the input icon
name with the '.iconset' file extension.

-o --output
Overrides the default output file name that iconutil uses to save
the converted '.iconset' or '.icns' files.

FILES
/usr/bin/iconutil


|

faviconを作る

1:画像を用意する(32x32px)
2:faviconにする



1:画像を用意する(32x32px)
最終的に減色されるので、グラデーション等を利用しない方がクリアに表示される


2:faviconにする
GraphicConverter グラフィックコンバーター【LINK】を利用するのが簡単です


ファイルをGraphicConverterで開いて
20240224043217_1150x526

別条件で保存する...から保存します
20240224043237_1482x686

ICO - Windows Icon (*.ico)を指定して ファイル名をfavicon.icoで保存
20240224043328_1152x898


この方法で作成すれば
16x16サイズと32x32サイズが同封されたマルチサイズタイプのicoファイルを自動生成してくれます
20240224043351_1192x652



HTML表記
<link rel="shortcut icon" type="image/vnd.microsoft.icon" href="/favicon.ico">


|

アプリケーションのアイコンを書き出す


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

#!/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 "UniformTypeIdentifiers"
use framework "AppKit"
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 NSApplicationDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidApplicationDirPathURL to ocidURLsArray's firstObject()
#
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidApplicationDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
set aliasDefaultLocation to (ocidApplicationDirPathURL's absoluteURL()) as alias
############
try
  ## アプリケーション選択時
  set listUTI to {"com.apple.application-bundle"}
  set strMes to ("アプリケーションを選択してください") as text
  set strPrompt to ("アプリケーションを選択してください") as text
  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles without multiple selections allowed and showing package contents) as alias
on error
log "エラーしました"
return "エラーしました"
end try
############
set strAppFilePath to (POSIX path of aliasFilePath) as text
set ocidAppFilePath to refMe's NSString's stringWithString:(strAppFilePath)
set ocidAppFilePathURL to refMe's NSURL's fileURLWithPath:(ocidAppFilePath)
#
set ocidPlistFilePathURL to ocidAppFilePathURL's URLByAppendingPathComponent:("Contents/Info.plist")
set listPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL) |error|:(reference)
set ocidPlistDict to (item 1 of listPlistDict)
if ocidPlistDict is (missing value) then
  set ocidPlistFilePathURL to ocidAppFilePathURL's URLByAppendingPathComponent:("WrappedBundle/Info.plist")
  set listPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL) |error|:(reference)
  set ocidPlistDict to (item 1 of listPlistDict)
end if

############
set ocidBundleID to ocidPlistDict's valueForKey:("CFBundleIdentifier")
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidPicturesDirPathURL to ocidURLsArray's firstObject()
set strSubPath to ("Icons/AppIcon/" & ocidBundleID & ".iconset") as text
set ocidIconsDirPathURL to ocidPicturesDirPathURL's URLByAppendingPathComponent:(strSubPath)
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidIconsDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
############
set ocidIconFileName to ocidPlistDict's valueForKey:("CFBundleIconFile")
#
if ocidIconFileName = (missing value) then
doExtractAssets(ocidAppFilePathURL, ocidIconsDirPathURL)
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  set boolDone to appSharedWorkspace's selectFile:(ocidIconsDirPathURL's |path|) inFileViewerRootedAtPath:(ocidIconsDirPathURL's |path|)
return "Icnsファイルの指定がありあません"
end if
set boolIcns to (ocidIconFileName's hasSuffix:("icns")) as boolean
set strSubPath to ("Contents/Resources/" & ocidIconFileName) as text
if boolIcns is true then
  set ocidIconFilePathURL to ocidAppFilePathURL's URLByAppendingPathComponent:(strSubPath)
else
  set ocidIconFilePathURL to ocidAppFilePathURL's URLByAppendingPathComponent:(strSubPath)
  set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:("icns")
end if
set ocidIconFileName to ocidIconFilePathURL's lastPathComponent()
############
set strIconFilePath to (ocidIconFilePathURL's |path|) as text
set strSaveDirPath to (ocidIconsDirPathURL's |path|) as text
try
  set strCommandText to ("/usr/bin/iconutil --convert iconset \"" & strIconFilePath & "\" -o \"" & strSaveDirPath & "\"") as text
do shell script strCommandText
end try
############
set ocidDistIconFilePathURL to ocidIconsDirPathURL's URLByAppendingPathComponent:(ocidIconFileName)
#
set listDone to appFileManager's copyItemAtURL:(ocidIconFilePathURL) toURL:(ocidDistIconFilePathURL) |error|:(reference)

############
set ocidAppPath to ocidDistIconFilePathURL's |path|
set ocidContainerDirPath to ocidIconsDirPathURL's |path|
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolDone to appSharedWorkspace's selectFile:(ocidAppPath) inFileViewerRootedAtPath:(ocidContainerDirPath)



return "処理終了"

#######################
#Assets.carからicnsファイル
#######################
to doExtractAssets(argAppFilePathURL, argIconsSaveDirPathURL)
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidFilePathURL to argAppFilePathURL's URLByAppendingPathComponent:("Contents/Resources/Assets.car") isDirectory:false
  set ocidFilePath to ocidFilePathURL's |path|
  set boolExists to appFileManager's fileExistsAtPath:(ocidFilePath)
  if boolExists is false then
    set ocidFilePathURL to argAppFilePathURL's URLByAppendingPathComponent:("WrappedBundle/Assets.car") isDirectory:false
    set ocidFilePath to ocidFilePathURL's |path|
    set boolExists to appFileManager's fileExistsAtPath:(ocidFilePath)
    if boolExists is false then
return "Assets.carが見つかりません"
    end if
  end if
  set strFilePath to ocidFilePath as text
  set strSaveDirPath to (argIconsSaveDirPathURL's |path|) as text
  try
    ###AppIcon指定時
    set strCommandText to ("/usr/bin/iconutil --convert iconset \"" & strFilePath & "\" AppIcon -o \"" & strSaveDirPath & "\"") as text
do shell script strCommandText
  on error
    ###システム設定の指定例
    set strCommandText to ("/usr/bin/iconutil --convert iconset \"" & strFilePath & "\" PrefApp -o \"" & strSaveDirPath & "\"") as text
do shell script strCommandText
  end try
  set ocidSaveIconFilePathURL to argIconsSaveDirPathURL's URLByAppendingPathComponent:("AppIcon.icns") isDirectory:false
  set strSaveIconFilePath to (ocidSaveIconFilePathURL's |path|) as text
  try
    set strCommandText to ("/usr/bin/iconutil --convert icns \"" & strSaveDirPath & "\" -o \"" & strSaveIconFilePath & "\" ") as text
do shell script strCommandText
  end try
end doExtractAssets











|

より以前の記事一覧

その他のカテゴリー

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