AppleScript Dock

DockTool ターミナルからDockに項目を追加削除する


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
(*
strJob はadd del
argPositionは登録場所 1から
またはDOCKから削除したいポジション
argAppFilePathはUNIXパス=/some/dir/some.app
削除の場合エラーよけで任意の文字列が必要

登録
DockTool.applescript add 3 /some/app/path/some\ appname.app
DockTool.applescript add 3 "/some/app/path/some appname.app"
削除
DockTool.applescript.applescript del 3 del
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "Appkit"
use framework "UniformTypeIdentifiers"
use scripting additions

property refMe : a reference to current application

on run {argJob, argPosition, argAppFilePath}

  set strJob to (argJob) as text
  if strJob is "add" then
    if argAppFilePath = (missing value) then
log "登録アプリのパス指定がありません"
return "処理を中止します"
    end if
  end if
  set strAppFilePath to (argAppFilePath) as text
  set numPosition to (argPosition) as integer

  #####
  set boolExists to doChkManagedPreferences()
  if boolExists = false then
log "管理された設定が無いので処理を続行します"
  else if boolDone = true then
return "設定が管理されているので処理を中止します"
  end if
  #####
  if strJob is "add" then
    set listResponse to doChkAppPathExists(strAppFilePath)
    if (item 1 of listResponse) = false then
return "指定のパスは存在しません処理を中止します"
    else if (item 1 of listResponse) = true then
set ocidAppPathURL to (item 2 of listResponse)
log "処理を開始します"
log "ファイルパス:" & strAppFilePath
log "上記のパスをDOCKの : " & numPosition & "番目に登録します"
    end if
  else if strJob is "del" then
log "処理を開始します"
log "Dockの " & numPosition & "番目の項目を"
log "削除します"
  end if
  
  ################################
  ####PLIST
  ################################
  set appFileManager to refMe's NSFileManager's defaultManager()
  ###URL
  set ocidURLArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidLibraryDirPathURL to ocidURLArray's firstObject()
  set ocidPlistPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/com.apple.dock.plist") isDirectory:(false)
  #####
  set boolDone to doMakeBackUp(ocidPlistPathURL)
  if boolDone = false then
log "バックアップの作成に失敗しました"
return "処理を中止します"
  else if boolDone = true then
log "バックアップ処理正常終了"
  end if
  
  ################################
  ##エラー制御したいのでNSDATA経由
  ################################
  set listReadData to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidPlistPathURL) options:(refMe's NSDataReadingMappedIfSafe) |error|:(reference)
  if (item 2 of listReadData) = (missing value) then
    set coidReadData to (item 1 of listReadData)
log "正常終了: NSDATA"
  else
log (item 2 of listReadData)'s localizedDescription() as text
return " NSDataへの読み込みに失敗しました"
  end if
  ################################
  ##NSPropertyListSerialization
  ################################
  ##可変DICTに変換
  #バイナリーモード
  set ocidFormat to (refMe's NSPropertyListBinaryFormat_v1_0)
  #可変DICTにする
  set ocidOption to (refMe's NSPropertyListMutableContainers)
  #シリアライゼーション
  set listReadPlistDict to refMe's NSPropertyListSerialization's propertyListWithData:(coidReadData) options:(ocidOption) format:(ocidFormat) |error|:(reference)
  if (item 2 of listReadPlistDict) = (missing value) then
log "正常終了: NSPropertyListSerialization"
    set ocidReadPlistDict to (item 1 of listReadPlistDict)
  else
log (item 2 of listReadPlistDict)'s localizedDescription() as text
return "Plist変換に失敗しました"
  end if
  set numCntAllKey to ocidReadPlistDict's allKeys()
  if (count of numCntAllKey) < 1 then
return "Plistの内容が不正です"
  end if
  
  ################################
  ##本処理 値を入れていく
  ################################
  #Dockのアプリケーションのリスト
  set ocidPersistentArray to ocidReadPlistDict's objectForKey:("persistent-apps")
  set numCntArray to ocidPersistentArray's |count|() as integer
  ###
    if numCntArray ≥ (numPosition - 1) then
ocidPersistentArray's removeObjectAtIndex:(numPosition - 1)
    else
log "ポジションの指定が登録数より大きいです"
log numCntArray & "より少ない数を指定してください"
log "登録"
log "DockTool.applescript add " & (numCntArray - 1) & " \"" & strAppFilePath & "\""
log "削除"
log "DockTool.applescript del " & (numCntArray - 1) & " del"
return "処理を終了します"
    end if

  ###削除
  if strJob is "del" then
ocidPersistentArray's removeObjectAtIndex:(numPosition - 1)
    ###追加
  else if strJob is "add" then
    ################################
    ####persistent-appsデータ生成
    ################################
    ##セットする可変DICT3つ
    set ocidSetDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:(0)
    set ocidSetTileDataDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:(0)
    set ocidSetFileDataDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:(0)
    ##アトリビュートを取得
    set ocidResourceKeyArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidResourceKeyArray's addObject:(refMe's NSURLCustomIconKey)
ocidResourceKeyArray's addObject:(refMe's NSURLIsApplicationKey)
ocidResourceKeyArray's addObject:(refMe's NSURLPathKey)
ocidResourceKeyArray's addObject:(refMe's NSURLLocalizedNameKey)
ocidResourceKeyArray's addObject:(refMe's NSURLContentModificationDateKey)
    #
    set listResponse to ocidAppPathURL's resourceValuesForKeys:(ocidResourceKeyArray) |error|:(reference)
    if (item 2 of listResponse) = (missing value) then
log "正常終了: resourceValuesForKeys"
      set ocidURLAttarDict to (item 1 of listResponse)
    else if (item 2 of listResponse) ≠ (missing value) then
log (item 2 of listResponse)'s localizedDescription() as text
return "resourceValuesForKeysに失敗しました"
    end if
    ##############【1】ROOT
    ###GUID実際はランダム番号だがNSFileSystemFileNumberを使う
    set listResponse to appFileManager's attributesOfItemAtPath:(ocidAppPathURL's |path|()) |error|:(reference)
    if (item 2 of listResponse) = (missing value) then
log "正常終了: attributesOfItemAtPath"
      set ocidFileAttarDict to (item 1 of listResponse)
    else if (item 2 of listResponse) ≠ (missing value) then
log (item 2 of listResponse)'s localizedDescription() as text
return "attributesOfItemAtPathに失敗しました"
    end if
    set numGUID to ocidFileAttarDict's objectForKey:(refMe's NSFileSystemFileNumber)
    set ocidIntValue to (refMe's NSNumber's numberWithInteger:(numGUID))
ocidSetDict's setValue:(numGUID) forKey:("GUID")
    ###tile-type
    set ocidStringValue to (refMe's NSString's stringWithString:("file-tile"))
ocidSetDict's setObject:(ocidStringValue) forKey:("tile-type")
    ##############【2】tile_data
    ####dock-extra
    set ocidBoolValue to (refMe's NSNumber's numberWithBool:false)
ocidSetTileDataDict's setObject:(ocidBoolValue) forKey:("dock-extra")
    ####dock-extra
    set ocidBoolValue to (refMe's NSNumber's numberWithBool:false)
ocidSetTileDataDict's setObject:(ocidBoolValue) forKey:("is-beta")
    ####bundle-identifier
    set ocidAppBunndle to (refMe's NSBundle's bundleWithURL:(ocidAppPathURL))
    set ocidBunndleID to ocidAppBunndle's bundleIdentifier
    set ocidStringValue to ocidBunndleID's UTF8String()
ocidSetTileDataDict's setObject:(ocidStringValue) forKey:("bundle-identifier")
    ####file-label"
    set ocidLocalizedName to (ocidURLAttarDict's objectForKey:(refMe's NSURLLocalizedNameKey))
    set ocidFileLabel to (ocidLocalizedName's stringByDeletingPathExtension())
    set ocidFileLabelString to ocidFileLabel's UTF8String()
ocidSetTileDataDict's setObject:(ocidFileLabelString) forKey:("file-label")
    ####file-mod-date
    set ocidModificationDate to (ocidURLAttarDict's objectForKey:(refMe's NSURLContentModificationDateKey))
    set ocidModDate to ocidModificationDate's timeIntervalSince1970
    set ocidIntValue to ocidModDate's intValue()
ocidSetTileDataDict's setObject:(ocidIntValue) forKey:("file-mod-date")
    ####parent-mod-date は今日の今
    set ocidNow to refMe's NSDate's now
    set ocidNowNo to ocidNow's timeIntervalSince1970
    set ocidIntValue to ocidNowNo's intValue
ocidSetTileDataDict's setObject:(ocidIntValue) forKey:("parent-mod-date")
    ####book
    set ocidOption to (refMe's NSURLBookmarkCreationWithSecurityScope)
    set listResponse to (ocidAppPathURL's bookmarkDataWithOptions:(ocidOption) includingResourceValuesForKeys:(ocidResourceKeyArray) relativeToURL:(missing value) |error|:(reference))
    if (item 2 of listResponse) = (missing value) then
log "正常終了: bookmarkDataWithOptions"
      set ocidBookMarkData to (item 1 of listResponse)
    else if (item 2 of listResponse) ≠ (missing value) then
log (item 2 of listResponse)'s localizedDescription() as text
return "BOOKMARKエイリアスデータの取得に失敗しました"
    end if
ocidSetTileDataDict's setObject:(ocidBookMarkData) forKey:("book")
    ####file-type
    # 169 Launchpad とMission Control
    # 41 それ以外はまぁ41で間違いなさそう
    if (ocidFileLabelString as text) is "Launchpad" then
      set ocidSetFileTypeValue to refMe's NSNumber's numberWithInteger:(169)
    else if (ocidFileLabelString as text) is "Mission Control" then
      set ocidSetFileTypeValue to refMe's NSNumber's numberWithInteger:(169)
    else
      set ocidSetFileTypeValue to refMe's NSNumber's numberWithInteger:(41)
    end if
(ocidSetTileDataDict's setObject:(ocidSetFileTypeValue) forKey:("file-type"))
    ##############【3】file_data
    ####_CFURLString
    set coidAbsoluteStringPath to ocidAppPathURL's absoluteString()
(ocidSetFileDataDict's setObject:(coidAbsoluteStringPath) forKey:("_CFURLString"))
    ####_CFURLStringType
    # 0 /File/Path
    # 15 file:// のURL形式
    set ocidIntValue to refMe's NSNumber's numberWithInteger:(15)
(ocidSetFileDataDict's setObject:(ocidIntValue) forKey:("_CFURLStringType"))
    ##############【4】セットするDICTにまとめる
(ocidSetTileDataDict's setObject:(ocidSetFileDataDict) forKey:("file-data"))
ocidSetDict's setObject:(ocidSetTileDataDict) forKey:("tile-data")
    ################################
    ####追加データを元のPLISTに戻す
    ################################
ocidPersistentArray's insertObject:(ocidSetDict) atIndex:(numPosition - 1)
  end if
  ################################
  ####保存
  ################################
  set listDone to ocidReadPlistDict's writeToURL:(ocidPlistPathURL) |error|:(reference)
  if (item 2 of listDone) = (missing value) then
log "ファイルの保存終了: writeToURL"
    
  else if (item 2 of listDone) ≠ (missing value) then
log (item 2 of listDone)'s localizedDescription() as text
return "ファイルの保存に失敗しました"
  end if
  
  
  ################################
  ###CFPreferencesを再起動
  ################################
  #####CFPreferencesを再起動させて変更後の値をロードさせる
  
  set strCommandText to "/usr/bin/killall cfprefsd" as text
do shell script strCommandText
  set strCommandText to "/bin/ps -ale | grep -v grep | grep 'com.apple.dock.extra'| awk '{print $2}'" as text
  try
    set strPid to (do shell script strCommandText) as text
log "com.apple.dock.extraのPID:" & strPid
    set strCommandText to "/usr/bin/kill - 9 " & strPid & "" as text
    try
do shell script strCommandText
    end try
  end try
log "終了しました Dockを再起動します"
  try
      set strCommandText to ("/usr/bin/killall Dock")
do shell script strCommandText
    end try
  (*
set strPlistPath to "/System/Library/LaunchAgents/com.apple.cfprefsd.xpc.agent.plist"
set strCommandText to ("/bin/launchctl stop -w \"" & strAgentPath & "\"")
try
do shell script strCommandText
end try
set strCommandText to ("/bin/launchctl start -w \"" & strAgentPath & "\"")
try
do shell script strCommandText
end try
set strPlistPath to "/System/Library/LaunchDaemons/com.apple.cfprefsd.xpc.daemon.plist"
set strCommandText to ("/bin/launchctl stop -w \"" & strAgentPath & "\"")
try
do shell script strCommandText
end try
set strCommandText to ("/bin/launchctl start -w \"" & strAgentPath & "\"")
try
do shell script strCommandText
end try
*)
  
  
  
end run
##############################
### 今の日付日間 テキスト
##############################
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


to doChkManagedPreferences()
  ################################
  ####Managed Preferencesチェック
  ################################
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSLocalDomainMask))
  set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
  #
  set ocidProcessInfo to refMe's NSProcessInfo's processInfo()
  set ocidEnvDict to ocidProcessInfo's environment()
  set strShortUserName to (ocidEnvDict's valueForKey:"USER") as text
  set strSetValue to ("/Managed Preferences/" & strShortUserName & "/com.apple.dock.plist") as text
  set ocidManagedPlistPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:(strSetValue) isDirectory:(false)
  set boolExists to appFileManager's fileExistsAtPath:(ocidManagedPlistPathURL's |path|())
  if boolExists is false then
log "管理された設定が無いので処理を続行します"
return false
  else if boolExists is true then
log "設定が管理されているので処理を中止します"
return true
  end if
end doChkManagedPreferences


to doChkAppPathExists(argAppFilePath)
  ################################
  ####パスと位置情報を受け取る
  ################################
  set appFileManager to refMe's NSFileManager's defaultManager()
  ##受け取ったパスの実存チェック
  set ocidAppPathStr to refMe's NSString's stringWithString:(argAppFilePath)
  set ocidAppPath to ocidAppPathStr's stringByStandardizingPath()
  set ocidAppPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidAppPath))
  set boolExists to appFileManager's fileExistsAtPath:(ocidAppPath)
  if boolExists = false then
log "指定のパスは存在しません処理を中止します"
return {false,ocidAppPathURL}
  else if boolExists = true then
log "処理を開始します"
return {true,ocidAppPathURL}
  end if
end doChkAppPathExists



to doMakeBackUp(argFilePathURl)
  ################################
  ####書類フォルダにバックアップ
  ################################
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDocumentDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidDocumentDirPathURL to ocidURLsArray's firstObject()
  #フォルダ名は日付
  set strDate to doGetDateNo("yyyyMMdd") as text
  set strSetValue to ("Apple/Preferences/" & strDate) as text
  set ocidBackUpDirPathURL to ocidDocumentDirPathURL's URLByAppendingPathComponent:(strSetValue) isDirectory:(true)
  set boolExists to appFileManager's fileExistsAtPath:(ocidBackUpDirPathURL's |path|()) isDirectory:(true)
  if boolExists = false then
log "バックアップ用のディレクトリを作ります"
log "場所は$HOME/Documents/Apple/Preferences/日付です"
    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 listDone to appFileManager's createDirectoryAtURL:(ocidBackUpDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
    if (item 1 of listDone) = true then
log "正常終了: createDirectoryAtURL"
    else if (item 1 of listDone) = false then
log (item 2 of listDone)'s localizedDescription() as text
log " バックアップ用のディレクトリの作成に失敗しました"
return
    end if
  else if boolExists = true then
log "バックアップ用のディレクトリはすでにありました"
  end if
  set ocidBackupFilePathURL to ocidBackUpDirPathURL's URLByAppendingPathComponent:("com.apple.dock.plist")
  set boolExists to appFileManager's fileExistsAtPath:(ocidBackupFilePathURL's |path|()) isDirectory:(false)
  if boolExists = true then
log "すでにバックアップがあるので今回はバックアップしません"
return true
  else if boolExists = false then
    set listDone to appFileManager's copyItemAtURL:(argFilePathURl) toURL:(ocidBackupFilePathURL) |error|:(reference)
    if (item 1 of listDone) = true then
log "設定ファイルのバックアップを作成しました"
return true
    else if (item 1 of listDone) = false then
log (item 2 of listDone)'s localizedDescription() as text
log " ファイルのコピーに失敗しました"
return false
    end if
  end if
end doMakeBackUp

|

[Dock] wvousホットコーナーの設定

0 = No Action 未設定
1 = No Action 何もしない
2 = Mission Control ミッションコントロール
3 = Application Windows
4 = Desktop デスクトップ
5 = Start Screen Saver スクリーンセイバー
6 = Disable Screen Saver スクリーンセイバー不要
7 = Dashboard 旧:ダッシュボード
10 = Put Display to Sleep スリープ
11 = Launchpad ランチパッド
12 = Notification Center 通知センター
13 = Lock Screen スクリーンロック
14 = Quick Note クイックメモ

Wvouscorner_20230803213401

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
#
(* MDM
https://developer.apple.com/documentation/devicemanagement/dock?language=objc
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "Appkit"
use framework "UniformTypeIdentifiers"
use scripting additions
property refMe : a reference to current application

################################
####設定項目
################################

###Plist=設定ファイルのバックアップファイルを作る?
###True=作る false =作らない
set boolMakeBackup to false as boolean

################################
####設定ファイル
################################
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLibraryDirURL to ocidURLsArray's firstObject()
set ocidPlistPathURL to ocidLibraryDirURL's URLByAppendingPathComponent:("Preferences/com.apple.dock.plist")
################################
####バックアップ
################################
if boolMakeBackup is true then
  set strDateno to (doGetDateNo("yyyyMMdd-hhmmss")) as text
  set strBackupPath to ("Preferences/com.apple.dock.plist.backup." & strDateno) as text
  set ocidBackupPlistPathURL to ocidLibraryDirURL's URLByAppendingPathComponent:(strBackupPath)
  set listDone to appFileManager's copyItemAtURL:(ocidPlistPathURL) toURL:(ocidBackupPlistPathURL) |error|:(reference)
end if
################################
####設定の内容 確認 変更
################################
set listReadPlistData to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL) |error|:(reference)
set ocidPlistDict to item 1 of listReadPlistData

###
(*
0 = No Action 未設定
1 = No Action 何もしない
2 = Mission Control ミッションコントロール
3 = Application Windows 
4 = Desktop デスクトップ
5 = Start Screen Saver スクリーンセイバー
6 = Disable Screen Saver スクリーンセイバー不要
7 = Dashboard 旧:ダッシュボード
10 = Put Display to Sleep スリープ
11 = Launchpad ランチパッド
12 = Notification Center 通知センター
13 = Lock Screen スクリーンロック
14 = Quick Note クイックメモ
*)
##上右
set ocidIntValue to refMe's NSNumber's numberWithInteger:(1)
ocidPlistDict's setValue:(ocidIntValue) forKey:("wvous-tr-corner")
##上左
set ocidIntValue to refMe's NSNumber's numberWithInteger:(1)
ocidPlistDict's setValue:(ocidIntValue) forKey:("wvous-tl-corner")
##下右
set ocidIntValue to refMe's NSNumber's numberWithInteger:(1)
ocidPlistDict's setValue:(ocidIntValue) forKey:("wvous-br-corner")
##下左
set ocidIntValue to refMe's NSNumber's numberWithInteger:(14)
ocidPlistDict's setValue:(ocidIntValue) forKey:("wvous-bl-corner")


########################
###保存
set ocidFormat to (refMe's NSPropertyListBinaryFormat_v1_0)
set listDoneSerialization to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFormat) options:0 |error|:(reference)
set ocidSavePlistData to (item 1 of listDoneSerialization)
set ocidOption to (refMe's NSDataWritingAtomic)
set listDone to ocidSavePlistData's writeToURL:(ocidPlistPathURL) options:(ocidOption) |error|:(reference)

################################
####Dock再起動
################################
set strBundleID to "com.apple.dock" as text
##起動中のアプリを取得して
set ocidAppListArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
####1以上ならアプリがあるって事なので
if (count of ocidAppListArray) ≠ 0 then
  repeat with itemAppListArray in ocidAppListArray
    set booleDone to itemAppListArray's terminate()
  end repeat
end if
repeat 10 times
  ####3秒まって
  delay 1
  set ocidAppListArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
  ###アプリケーションが無いなら
  if (count of ocidAppListArray) = 0 then
    ###起動
    set ocidAppPathURL to doGetBundleID2AppURL(strBundleID)
    tell current application
      set strName to name as text
    end tell
    set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
    set ocidOpenConfig to refMe's NSWorkspaceOpenConfiguration's configuration
(ocidOpenConfig's setActivates:(refMe's NSNumber's numberWithBool:true))
    if strName is "osascript" then
      set boolDone to (run script (appSharedWorkspace's openApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value)))
    else
      set boolDone to (activate (appSharedWorkspace's openApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value)))
    end if
    log "手動で起動"
  else
    ###起動が確認できたら処理終了
    exit repeat
  end if
end repeat

################################
####ランチパッド起動
################################
set strBundleID to ("com.apple.launchpad.launcher") as text
##起動中のアプリを取得して
set ocidAppList to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
##数えて
set numCntAppList to (count of ocidAppList) as integer
if numCntAppList = 0 then
  set ocidAppPathURL to doGetBundleID2AppURL(strBundleID)
  set aliasAppPath to (ocidAppPathURL's absoluteURL()) as alias
  tell application "Finder"
    open aliasAppPath
  end tell
end if



################################
####バックアップ用の日付
################################
to doGetDateNo(strDateFormat)
  ####日付情報の取得
  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")
ocidNSDateFormatter's setDateFormat:strDateFormat
  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo
###################################
### バンドルIDからアプリケーションURL
###################################
to doGetBundleID2AppURL(argBundleID)
  set strBundleID to argBundleID as text
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  ##バンドルIDからアプリケーションのURLを取得
  set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(argBundleID))
  if ocidAppBundle ≠ (missing value) then
    set ocidAppPathURL to ocidAppBundle's bundleURL()
  else if ocidAppBundle = (missing value) then
    set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(argBundleID))
  end if
  ##予備(アプリケーションのURL)
  if ocidAppPathURL = (missing value) then
    tell application "Finder"
      try
set aliasAppApth to (application file id strBundleID) as alias
set strAppPath to (POSIX path of aliasAppApth) as text
set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
set strAppPath to strAppPathStr's stringByStandardizingPath()
set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(strAppPath) isDirectory:true
      on error
return "アプリケーションが見つかりませんでした"
      end try
    end tell
  end if
return ocidAppPathURL
end doGetBundleID2AppURL

|

[Dock]基本的な設定のみ


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
#
(* MDM
https://developer.apple.com/documentation/devicemanagement/dock?language=objc
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "Appkit"
use framework "UniformTypeIdentifiers"
use scripting additions
property refMe : a reference to current application

################################
####設定項目
################################

###Plist=設定ファイルのバックアップファイルを作る?
###True=作る false =作らない
set boolMakeBackup to false as boolean

################################
####設定ファイル
################################
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLibraryDirURL to ocidURLsArray's firstObject()
set ocidPlistPathURL to ocidLibraryDirURL's URLByAppendingPathComponent:("Preferences/com.apple.dock.plist")
################################
####バックアップ
################################
if boolMakeBackup is true then
  set strDateno to (doGetDateNo("yyyyMMdd-hhmmss")) as text
  set strBackupPath to ("Preferences/com.apple.dock.plist.backup." & strDateno) as text
  set ocidBackupPlistPathURL to ocidLibraryDirURL's URLByAppendingPathComponent:(strBackupPath)
  set listDone to appFileManager's copyItemAtURL:(ocidPlistPathURL) toURL:(ocidBackupPlistPathURL) |error|:(reference)
end if
################################
####設定の内容 確認 変更
################################
set listReadPlistData to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL) |error|:(reference)
set ocidPlistDict to item 1 of listReadPlistData

set ocidBoolValue to (refMe's NSNumber's numberWithBool:(false))
ocidPlistDict's setValue:(ocidBoolValue) forKey:("autohide")
ocidPlistDict's setValue:(ocidBoolValue) forKey:("launchanim")
set ocidBoolValue to (refMe's NSNumber's numberWithBool:(true))
ocidPlistDict's setValue:(ocidBoolValue) forKey:("mouse-over-hilite-stack")
ocidPlistDict's setValue:(ocidBoolValue) forKey:("expose-group-apps")
ocidPlistDict's setValue:(ocidBoolValue) forKey:("show-process-indicators")
ocidPlistDict's setValue:(ocidBoolValue) forKey:("minimize-to-application")

### Possible Values: bottom, left, right
set ocidStringValue to refMe's NSString's stringWithString:("right")
ocidPlistDict's setValue:(ocidStringValue) forKey:("orientation")
### Possible Values: genie, scale
set ocidStringValue to refMe's NSString's stringWithString:("scale")
ocidPlistDict's setValue:(ocidStringValue) forKey:("mineffect")

###
set ocidLocation to refMe's NSLocale's currentLocale()
set ocidLocalID to ocidLocation's localeIdentifier()
set ocidContryCode to ocidLocation's objectForKey:(refMe's NSLocaleCountryCode)

#set ocidStringValue to refMe's NSString's stringWithString:("ja_JP:(null)")
set ocidStringValue to refMe's NSString's stringWithString:(ocidLocalID)
ocidPlistDict's setValue:(ocidStringValue) forKey:("loc")
set ocidStringValue to refMe's NSString's stringWithString:(ocidContryCode)
ocidPlistDict's setValue:(ocidStringValue) forKey:("region")

##Minimum Value: 16 Maximum Value: 128
set ocidIntValue to refMe's NSNumber's numberWithInteger:(52)
ocidPlistDict's setValue:(ocidIntValue) forKey:("tilesize")
set ocidIntValue to refMe's NSNumber's numberWithInteger:(128)
ocidPlistDict's setValue:(ocidIntValue) forKey:("largesize")
###
(*
0 = No Action 未設定
1 = No Action 何もしない
2 = Mission Control ミッションコントロール
3 = Application Windows 
4 = Desktop デスクトップ
5 = Start Screen Saver スクリーンセイバー
6 = Disable Screen Saver スクリーンセイバー不要
7 = Dashboard 旧:ダッシュボード
10 = Put Display to Sleep スリープ
11 = Launchpad ランチパッド
12 = Notification Center 通知センター
13 = Lock Screen スクリーンロック
14 = Quick Note クイックメモ
*)
set ocidIntValue to refMe's NSNumber's numberWithInteger:(1)
ocidPlistDict's setValue:(ocidIntValue) forKey:("wvous-tr-corner")
set ocidIntValue to refMe's NSNumber's numberWithInteger:(1)
ocidPlistDict's setValue:(ocidIntValue) forKey:("wvous-tl-corner")
set ocidIntValue to refMe's NSNumber's numberWithInteger:(1)
ocidPlistDict's setValue:(ocidIntValue) forKey:("wvous-br-corner")
set ocidIntValue to refMe's NSNumber's numberWithInteger:(14)
ocidPlistDict's setValue:(ocidIntValue) forKey:("wvous-bl-corner")


########################
###保存
set ocidFormat to (refMe's NSPropertyListBinaryFormat_v1_0)
set listDoneSerialization to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFormat) options:0 |error|:(reference)
set ocidSavePlistData to (item 1 of listDoneSerialization)
set ocidOption to (refMe's NSDataWritingAtomic)
set listDone to ocidSavePlistData's writeToURL:(ocidPlistPathURL) options:(ocidOption) |error|:(reference)

################################
####Dock再起動
################################
set strBundleID to "com.apple.dock" as text
##起動中のアプリを取得して
set ocidAppListArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
####1以上ならアプリがあるって事なので
if (count of ocidAppListArray) ≠ 0 then
  repeat with itemAppListArray in ocidAppListArray
    set booleDone to itemAppListArray's terminate()
  end repeat
end if
repeat 10 times
  ####3秒まって
  delay 1
  set ocidAppListArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
  ###アプリケーションが無いなら
  if (count of ocidAppListArray) = 0 then
    ###起動
    set ocidAppPathURL to doGetBundleID2AppURL(strBundleID)
    tell current application
      set strName to name as text
    end tell
    set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
    set ocidOpenConfig to refMe's NSWorkspaceOpenConfiguration's configuration
(ocidOpenConfig's setActivates:(refMe's NSNumber's numberWithBool:true))
    if strName is "osascript" then
      set boolDone to (run script (appSharedWorkspace's openApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value)))
    else
      set boolDone to (activate (appSharedWorkspace's openApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value)))
    end if
    log "手動で起動"
  else
    ###起動が確認できたら処理終了
    exit repeat
  end if
end repeat

################################
####ランチパッド起動
################################
set strBundleID to ("com.apple.launchpad.launcher") as text
##起動中のアプリを取得して
set ocidAppList to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
##数えて
set numCntAppList to (count of ocidAppList) as integer
if numCntAppList = 0 then
  set ocidAppPathURL to doGetBundleID2AppURL(strBundleID)
  set aliasAppPath to (ocidAppPathURL's absoluteURL()) as alias
  tell application "Finder"
    open aliasAppPath
  end tell
end if



################################
####バックアップ用の日付
################################
to doGetDateNo(strDateFormat)
  ####日付情報の取得
  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")
ocidNSDateFormatter's setDateFormat:strDateFormat
  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo
###################################
### バンドルIDからアプリケーションURL
###################################
to doGetBundleID2AppURL(argBundleID)
  set strBundleID to argBundleID as text
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  ##バンドルIDからアプリケーションのURLを取得
  set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(argBundleID))
  if ocidAppBundle ≠ (missing value) then
    set ocidAppPathURL to ocidAppBundle's bundleURL()
  else if ocidAppBundle = (missing value) then
    set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(argBundleID))
  end if
  ##予備(アプリケーションのURL)
  if ocidAppPathURL = (missing value) then
    tell application "Finder"
      try
set aliasAppApth to (application file id strBundleID) as alias
set strAppPath to (POSIX path of aliasAppApth) as text
set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
set strAppPath to strAppPathStr's stringByStandardizingPath()
set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(strAppPath) isDirectory:true
      on error
return "アプリケーションが見つかりませんでした"
      end try
    end tell
  end if
return ocidAppPathURL
end doGetBundleID2AppURL

|

[Dock]『wvous-corner』ホットコーナー  com.apple.dock.plistの設定値

com.apple.dock.plistの設定値
アップルスクリプトを実行とか…あればいいのに



wvous-tr-corner トップ ライト
wvous-tl-corner トップ レフト
wvous-br-corner ボトム ライト
wvous-bl-corner ボトム レフト


0 = No Action 未設定
1 = No Action 何もしない
2 = Mission Control ミッションコントロール
3 = Application Windows
4 = Desktop デスクトップ
5 = Start Screen Saver スクリーンセイバー
6 = Disable Screen Saver スクリーンセイバー不要
7 = Dashboard 旧:ダッシュボード
10 = Put Display to Sleep スリープ
11 = Launchpad ランチパッド
12 = Notification Center 通知センター
13 = Lock Screen スクリーンロック
14 = Quick Note クイックメモ


Wvouscorner

|

[Launchpad]ランチパッド起動

ものすごく面倒くさい方法で起動させています(なので参考で)

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

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

property refMe : a reference to current application

set strBundleID to ("com.apple.launchpad.launcher") as text

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

##起動中のアプリを取得して
set ocidAppList to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
##数えて
set numCntAppList to (count of ocidAppList) as integer
if numCntAppList = 0 then
  
  set ocidAppPathURL to doGetBundleID2AppURL(strBundleID)
  set aliasAppPath to (ocidAppPathURL's absoluteURL()) as alias
  tell current application
    set strName to name as text
  end tell
  
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  set ocidOpenConfig to refMe's NSWorkspaceOpenConfiguration's configuration
(ocidOpenConfig's setActivates:(refMe's NSNumber's numberWithBool:true))
  if strName is "osascript" then
    try
      set boolDone to (activate (appSharedWorkspace's openApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value)))
    on error
      tell application "Finder"
open aliasAppPath
      end tell
    end try
  else
    try
      set boolDone to (activate (appSharedWorkspace's openApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value)))
    on error
      tell application "Finder"
open aliasAppPath
      end tell
    end try
  end if
  
end if

###################################
### バンドルIDからアプリケーションURL
###################################
to doGetBundleID2AppURL(argBundleID)
  set strBundleID to argBundleID as text
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  ##バンドルIDからアプリケーションのURLを取得
  set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(argBundleID))
  if ocidAppBundle ≠ (missing value) then
    set ocidAppPathURL to ocidAppBundle's bundleURL()
  else if ocidAppBundle = (missing value) then
    set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(argBundleID))
  end if
  ##予備(アプリケーションのURL)
  if ocidAppPathURL = (missing value) then
    tell application "Finder"
      try
set aliasAppApth to (application file id strBundleID) as alias
set strAppPath to (POSIX path of aliasAppApth) as text
set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
set strAppPath to strAppPathStr's stringByStandardizingPath()
set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(strAppPath) isDirectory:true
      on error
return "アプリケーションが見つかりませんでした"
      end try
    end tell
  end if
return ocidAppPathURL
end doGetBundleID2AppURL

|

[Launchpad]ランチパッドの縦横行列数を変更


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
#ランチパッドの縦横行列数の変更
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "Appkit"
use framework "UniformTypeIdentifiers"
use scripting additions
property refMe : a reference to current application

################################
####設定項目
################################
###行Rows
set numCntRows to 5 as integer
###列Columns
set numCntColumns to 7 as integer

###並び替えする=True しない=False
set boolSort to true as boolean

###Plist=設定ファイルのバックアップファイルを作る?
###True=作る false =作らない
set boolMakeBackup to false as boolean

################################
####設定ファイル
################################
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLibraryDirURL to ocidURLsArray's firstObject()
set ocidPlistPathURL to ocidLibraryDirURL's URLByAppendingPathComponent:("Preferences/com.apple.dock.plist")
################################
####バックアップ
################################
set strDateno to (doGetDateNo("yyyyMMdd-hhmmss")) as text
set strBackupPath to ("Preferences/com.apple.dock.plist.backup." & strDateno) as text
set ocidBackupPlistPathURL to ocidLibraryDirURL's URLByAppendingPathComponent:(strBackupPath)
if boolMakeBackup is true then
  set listDone to appFileManager's copyItemAtURL:(ocidPlistPathURL) toURL:(ocidBackupPlistPathURL) |error|:(reference)
end if
################################
####設定の内容 確認 変更
################################
##set listReadPlistData to refMe's NSMutableDictionary's dictionaryWithContentsOfURL:(ocidPlistPathURL) |error|:(reference)
set listReadPlistData to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL) |error|:(reference)
set ocidPlistDict to item 1 of listReadPlistData
###行Rows
log "行Rows変更前:" & (ocidPlistDict's valueForKey:("springboard-rows"))
###列Columns
log "列Columns変更前:" & (ocidPlistDict's valueForKey:("springboard-columns"))
########################
###行Rows
set ocidIntRows to refMe's NSNumber's numberWithInteger:(numCntRows)
ocidPlistDict's setValue:(ocidIntRows) forKey:("springboard-rows")
###列Columns
set ocidIntColumns to refMe's NSNumber's numberWithInteger:(numCntColumns)
ocidPlistDict's setValue:(ocidIntColumns) forKey:("springboard-columns")
###並び順リセット
if boolSort with to then
  set ocidBool to (refMe's NSNumber's numberWithBool:(true))
ocidPlistDict's setValue:(ocidBool) forKey:("ResetLaunchPad")
else
  set ocidBool to (refMe's NSNumber's numberWithBool:(false))
ocidPlistDict's setValue:(ocidBool) forKey:("ResetLaunchPad")
end if
log "#####変更処理実行"
###行Rows
log "行Rows変更後:" & (ocidPlistDict's valueForKey:("springboard-rows"))
###列Columns
log "列Columns変更後:" & (ocidPlistDict's valueForKey:("springboard-columns"))
###保存
##set boolDone to ocidPlistDict's writeToURL:(ocidPlistPathURL) atomically:(true)
set ocidFormat to (refMe's NSPropertyListBinaryFormat_v1_0)
set listDoneSerialization to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFormat) options:0 |error|:(reference)
set ocidSavePlistData to (item 1 of listDoneSerialization)
set ocidOption to (refMe's NSDataWritingAtomic)
set listDone to ocidSavePlistData's writeToURL:(ocidPlistPathURL) options:(ocidOption) |error|:(reference)

################################
####Dock再起動
################################
set strBundleID to "com.apple.dock" as text
##起動中のアプリを取得して
set ocidAppListArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
####1以上ならアプリがあるって事なので
if (count of ocidAppListArray) ≠ 0 then
  repeat with itemAppListArray in ocidAppListArray
    set booleDone to itemAppListArray's terminate()
  end repeat
end if
repeat 10 times
  ####3秒まって
  delay 1
  set ocidAppListArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
  ###アプリケーションが無いなら
  if (count of ocidAppListArray) = 0 then
    ###起動
    set ocidAppPathURL to doGetBundleID2AppURL(strBundleID)
    tell current application
      set strName to name as text
    end tell
    set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
    set ocidOpenConfig to refMe's NSWorkspaceOpenConfiguration's configuration
(ocidOpenConfig's setActivates:(refMe's NSNumber's numberWithBool:true))
    if strName is "osascript" then
      set boolDone to (run script (appSharedWorkspace's openApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value)))
    else
      set boolDone to (activate (appSharedWorkspace's openApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value)))
    end if
    log "手動で起動"
  else
    ###起動が確認できたら処理終了
    exit repeat
  end if
end repeat

################################
####ランチパッド起動
################################
set strBundleID to ("com.apple.launchpad.launcher") as text
##起動中のアプリを取得して
set ocidAppList to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
##数えて
set numCntAppList to (count of ocidAppList) as integer
if numCntAppList = 0 then
  set ocidAppPathURL to doGetBundleID2AppURL(strBundleID)
  set aliasAppPath to (ocidAppPathURL's absoluteURL()) as alias
  tell application "Finder"
    open aliasAppPath
  end tell
end if



################################
####バックアップ用の日付
################################
to doGetDateNo(strDateFormat)
  ####日付情報の取得
  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")
ocidNSDateFormatter's setDateFormat:strDateFormat
  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo
###################################
### バンドルIDからアプリケーションURL
###################################
to doGetBundleID2AppURL(argBundleID)
  set strBundleID to argBundleID as text
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  ##バンドルIDからアプリケーションのURLを取得
  set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(argBundleID))
  if ocidAppBundle ≠ (missing value) then
    set ocidAppPathURL to ocidAppBundle's bundleURL()
  else if ocidAppBundle = (missing value) then
    set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(argBundleID))
  end if
  ##予備(アプリケーションのURL)
  if ocidAppPathURL = (missing value) then
    tell application "Finder"
      try
set aliasAppApth to (application file id strBundleID) as alias
set strAppPath to (POSIX path of aliasAppApth) as text
set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
set strAppPath to strAppPathStr's stringByStandardizingPath()
set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(strAppPath) isDirectory:true
      on error
return "アプリケーションが見つかりませんでした"
      end try
    end tell
  end if
return ocidAppPathURL
end doGetBundleID2AppURL

|

[Launchpad]ランチパッドのDBをゴミ箱に入れて完全リセット(不具合時用)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
# ランチパッドのDBをゴミ箱に入れる事で完全リセット
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "Appkit"
use framework "UniformTypeIdentifiers"
use scripting additions

property refMe : a reference to current application
property refNSString : a reference to refMe's NSString

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


################################
####設定項目
################################
###行Rows
set numCntRows to 5 as integer
###列Columns
set numCntColumns to 7 as integer
###Plist=設定ファイルのバックアップファイルを作る?
###True=作る false =作らない
set boolMakeBackup to false as boolean

################################
####設定ファイル
################################
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLibraryDirURL to ocidURLsArray's firstObject()
set ocidPlistPathURL to ocidLibraryDirURL's URLByAppendingPathComponent:("Preferences/com.apple.dock.plist")
################################
####バックアップ
################################
set strDateno to (doGetDateNo("yyyyMMdd-hhmmss")) as text
set strBackupPath to ("Preferences/com.apple.dock.plist.backup." & strDateno) as text
set ocidBackupPlistPathURL to ocidLibraryDirURL's URLByAppendingPathComponent:(strBackupPath)
if boolMakeBackup is true then
  set listDone to appFileManager's copyItemAtURL:(ocidPlistPathURL) toURL:(ocidBackupPlistPathURL) |error|:(reference)
end if
################################
####設定の内容 確認 変更
################################
##set listReadPlistData to refMe's NSMutableDictionary's dictionaryWithContentsOfURL:(ocidPlistPathURL) |error|:(reference)
set listReadPlistData to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL) |error|:(reference)
set ocidPlistDict to item 1 of listReadPlistData
###行Rows
log "行Rows変更前:" & (ocidPlistDict's valueForKey:("springboard-rows"))
###列Columns
log "列Columns変更前:" & (ocidPlistDict's valueForKey:("springboard-columns"))
########################
###行Rows
set ocidIntRows to refMe's NSNumber's numberWithInteger:(numCntRows)
ocidPlistDict's setValue:(ocidIntRows) forKey:("springboard-rows")
###列Columns
set ocidIntColumns to refMe's NSNumber's numberWithInteger:(numCntColumns)
ocidPlistDict's setValue:(ocidIntColumns) forKey:("springboard-columns")
###並び順リセット
set ocidBool to (refMe's NSNumber's numberWithBool:(true))
ocidPlistDict's setValue:(ocidBool) forKey:("ResetLaunchPad")
log "#####変更処理実行"
###行Rows
log "行Rows変更後:" & (ocidPlistDict's valueForKey:("springboard-rows"))
###列Columns
log "列Columns変更後:" & (ocidPlistDict's valueForKey:("springboard-columns"))
###保存
##set boolDone to ocidPlistDict's writeToURL:(ocidPlistPathURL) atomically:(true)
set ocidFormat to (refMe's NSPropertyListBinaryFormat_v1_0)
set listDoneSerialization to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFormat) options:0 |error|:(reference)
set ocidSavePlistData to (item 1 of listDoneSerialization)
set ocidOption to (refMe's NSDataWritingAtomic)
set listDone to ocidSavePlistData's writeToURL:(ocidPlistPathURL) options:(ocidOption) |error|:(reference)
################################
####LaunchPadDBをゴミ箱に入れる
################################
set ocidTemporaryDirPathURL to objFileManager's temporaryDirectory()
set ocidTemporaryDirPathURL to ocidTemporaryDirPathURL's URLByDeletingLastPathComponent()
set ocidGo2TrashURL to ocidTemporaryDirPathURL's URLByAppendingPathComponent:("0/com.apple.dock.launchpad") isDirectory:(true)
set listDone to (appFileManager's trashItemAtURL:(ocidGo2TrashURL) resultingItemURL:(missing value) |error|:(reference))

################################
####Dock再起動
################################
set strBundleID to "com.apple.dock" as text
##起動中のアプリを取得して
set ocidAppListArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
####1以上ならアプリがあるって事なので
if (count of ocidAppListArray) ≠ 0 then
  repeat with itemAppListArray in ocidAppListArray
    set booleDone to itemAppListArray's terminate()
  end repeat
end if
repeat 10 times
  ####3秒まって
  delay 1
  set ocidAppListArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
  ###アプリケーションが無いなら
  if (count of ocidAppListArray) = 0 then
    ###起動
    set ocidAppPathURL to doGetBundleID2AppURL(strBundleID)
    tell current application
      set strName to name as text
    end tell
    set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
    set ocidOpenConfig to refMe's NSWorkspaceOpenConfiguration's configuration
(ocidOpenConfig's setActivates:(refMe's NSNumber's numberWithBool:true))
    if strName is "osascript" then
      set boolDone to (run script (appSharedWorkspace's openApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value)))
    else
      set boolDone to (activate (appSharedWorkspace's openApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value)))
    end if
    log "手動で起動"
  else
    ###起動が確認できたら処理終了
    exit repeat
  end if
end repeat

################################
####ランチパッド起動
################################
set strBundleID to ("com.apple.launchpad.launcher") as text
##起動中のアプリを取得して
set ocidAppList to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
##数えて
set numCntAppList to (count of ocidAppList) as integer
if numCntAppList = 0 then
  set ocidAppPathURL to doGetBundleID2AppURL(strBundleID)
  set aliasAppPath to (ocidAppPathURL's absoluteURL()) as alias
  tell application "Finder"
    open aliasAppPath
  end tell
end if


################################
####バックアップ用の日付
################################
to doGetDateNo(strDateFormat)
  ####日付情報の取得
  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")
ocidNSDateFormatter's setDateFormat:strDateFormat
  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo
###################################
### バンドルIDからアプリケーションURL
###################################
to doGetBundleID2AppURL(argBundleID)
  set strBundleID to argBundleID as text
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  ##バンドルIDからアプリケーションのURLを取得
  set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(argBundleID))
  if ocidAppBundle ≠ (missing value) then
    set ocidAppPathURL to ocidAppBundle's bundleURL()
  else if ocidAppBundle = (missing value) then
    set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(argBundleID))
  end if
  ##予備(アプリケーションのURL)
  if ocidAppPathURL = (missing value) then
    tell application "Finder"
      try
set aliasAppApth to (application file id strBundleID) as alias
set strAppPath to (POSIX path of aliasAppApth) as text
set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
set strAppPath to strAppPathStr's stringByStandardizingPath()
set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(strAppPath) isDirectory:true
      on error
return "アプリケーションが見つかりませんでした"
      end try
    end tell
  end if
return ocidAppPathURL
end doGetBundleID2AppURL


return


|

[Launchpad]Dock再起動


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

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

property refMe : a reference to current application

set strBundleID to "com.apple.dock" as text

##起動中のアプリを取得して
set ocidAppListArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)

####1以上ならアプリがあるって事なので
if (count of ocidAppListArray) ≠ 0 then
  repeat with itemAppListArray in ocidAppListArray
    set booleDone to itemAppListArray's terminate()
  end repeat
end if

repeat 10 times
  ####3秒まって
  delay 1
  set ocidAppListArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
  ###アプリケーションが無いなら
  if (count of ocidAppListArray) = 0 then
    ###起動
    set ocidAppPathURL to doGetBundleID2AppURL(strBundleID)
    tell current application
      set strName to name as text
    end tell
    set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
    set ocidOpenConfig to refMe's NSWorkspaceOpenConfiguration's configuration
(ocidOpenConfig's setActivates:(refMe's NSNumber's numberWithBool:true))
    if strName is "osascript" then
      set boolDone to (run script (appSharedWorkspace's openApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value)))
    else
      set boolDone to (activate (appSharedWorkspace's openApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value)))
    end if
    log "手動で起動"
  else
    ###起動が確認できたら処理終了
    exit repeat
  end if
end repeat

return "処理終了"

###################################
### バンドルIDからアプリケーションURL
###################################
to doGetBundleID2AppURL(argBundleID)
  set strBundleID to argBundleID as text
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  ##バンドルIDからアプリケーションのURLを取得
  set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(argBundleID))
  if ocidAppBundle ≠ (missing value) then
    set ocidAppPathURL to ocidAppBundle's bundleURL()
  else if ocidAppBundle = (missing value) then
    set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(argBundleID))
  end if
  ##予備(アプリケーションのURL)
  if ocidAppPathURL = (missing value) then
    tell application "Finder"
      try
set aliasAppApth to (application file id strBundleID) as alias
set strAppPath to (POSIX path of aliasAppApth) as text
set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
set strAppPath to strAppPathStr's stringByStandardizingPath()
set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(strAppPath) isDirectory:true
      on error
return "アプリケーションが見つかりませんでした"
      end try
    end tell
  end if
return ocidAppPathURL
end doGetBundleID2AppURL

|

[persistent-apps]Dockにアプリケーションを登録する(改良)

挿入位置の選択をわかりやすくした

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

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

property refMe : a reference to current application

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

####################################
###ユーザーアプリケーションフォルダ
set ocidURLArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationDirectory) inDomains:(refMe's NSUserDomainMask))
log className() of ocidURLArray as text
set ocidApplicationDirPathURL to ocidURLArray's firstObject()
set aliasDefaultLocation to (ocidApplicationDirPathURL's absoluteURL()) as alias
set ocidLocalizedPathURL to ocidApplicationDirPathURL's URLByAppendingPathComponent:(".localized")
###フォルダなければ作る 488 = 700
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolDone to appFileManager's createDirectoryAtURL:(ocidApplicationDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
###localizedの空ファイルも作る
set ocidLocalizedPath to ocidLocalizedPathURL's |path|()
set listBoolDone to appFileManager's createFileAtPath:(ocidLocalizedPath) |contents|:(missing value) attributes:(ocidAttrDict)
####################################
###ダイアログを前面に出す
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 listUTI to {"com.apple.application-bundle"}
set strPromptText to "アプリケーションを選んでください" as text
set strPromptMes to "アプリケーションを選んでください" as text
set aliasFilePath to (choose file (strPromptMes) with prompt (strPromptText) default location (aliasDefaultLocation) of type (listUTI) with invisibles without multiple selections allowed and showing package contents) as alias
###追加するパス
set strFilePath to POSIX path of aliasFilePath
set ocidFilePath to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePath's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:true

################################
####Plist読み込み
################################
###URL
set ocidURLArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLibraryDirPathURL to ocidURLArray's firstObject()
set ocidPlistPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/com.apple.dock.plist")
###読み込み
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
################################
####インサート位置
################################
set ocidPersistentArray to ocidPlistDict's objectForKey:"persistent-apps"
set numCntArray to ocidPersistentArray's |count|() as integer
################################
##作ったけど使わなかったDict
set ocidPersistentDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set listInsertPosision to {} as list
repeat with numNo from 0 to (numCntArray - 1) by 1
  set coidItemDict to (ocidPersistentArray's objectAtIndex:(numNo))
  set strLabel to (coidItemDict's valueForKeyPath:"tile-data.file-label") as text
  set recordAddRec to (run script "return {|" & numNo & "|:\"" & strLabel & "\"} ") as record
(ocidPersistentDict's addEntriesFromDictionary:recordAddRec)
  ##テキストにして
  set strAddList to ("" & numNo & ":" & strLabel & "") as text
  ##リストに追加
  set end of listInsertPosision to strAddList
end repeat
####
log listInsertPosision as list
try
  set listResponse to (choose from list listInsertPosision with title "選んでください" with prompt "挿入位置\r選んだ項目の前に挿入されます" default items (item 1 of listInsertPosision) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
  log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
end if
set strInsertPosision to (item 1 of listResponse) as text
set AppleScript's text item delimiters to ":"
set listItemInsertPosision to every text item of strInsertPosision
set AppleScript's text item delimiters to ""
set numInsertPosision to (item 1 of listItemInsertPosision) as integer

################################
####persistent-appsデータ生成
################################
set ocidAddDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
###GUID実際はランダム番号だがNSFileSystemFileNumberを使う
set listPathAttar to appFileManager's attributesOfItemAtPath:(ocidFilePath) |error|:(reference)
set ocidAttar to item 1 of listPathAttar
set numGUID to ocidAttar's valueForKey:(refMe's NSFileSystemFileNumber)
set ocidIntValue to (refMe's NSNumber's numberWithInteger:(numGUID))
ocidAddDict's setValue:(numGUID) forKey:("GUID")
###
set ocidStringValue to (refMe's NSString's stringWithString:("file-tile"))
ocidAddDict's setValue:(ocidStringValue) forKey:("tile-type")
################################
set ocidAddTitleDataDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
####dock-extra
set ocidBoolValue to (refMe's NSNumber's numberWithBool:false)
ocidAddTitleDataDict's setValue:(ocidBoolValue) forKey:("dock-extra")
####dock-extra
set ocidBoolValue to (refMe's NSNumber's numberWithBool:false)
ocidAddTitleDataDict's setValue:(ocidBoolValue) forKey:("is-beta")
####bundle-identifier
set ocidAppBunndle to (refMe's NSBundle's bundleWithURL:(ocidFilePathURL))
set ocidBunndleID to ocidAppBunndle's bundleIdentifier
set ocidStringValue to ocidBunndleID's UTF8String()
ocidAddTitleDataDict's setValue:(ocidStringValue) forKey:("bundle-identifier")
####file-label"
set listAttributesDict to ocidFilePathURL's resourceValuesForKeys:({refMe's NSURLLocalizedNameKey}) |error|:(reference)
set ocidAttributesDict to (item 1 of listAttributesDict)
set ocidLocalizedName to (ocidAttributesDict's objectForKey:(refMe's NSURLLocalizedNameKey))
set ocidFileLabel to (ocidLocalizedName's stringByDeletingPathExtension())
set ocidStringValue to ocidFileLabel's UTF8String()
ocidAddTitleDataDict's setValue:(ocidStringValue) forKey:("file-label")
####file-mod-date
set listAttributesDict to ocidFilePathURL's resourceValuesForKeys:({refMe's NSURLContentModificationDateKey}) |error|:(reference)
set ocidAttributesDict to (item 1 of listAttributesDict)
set ocidModificationDate to (ocidAttributesDict's objectForKey:(refMe's NSURLContentModificationDateKey))
set ocidModDate to ocidModificationDate's timeIntervalSince1970
set ocidIntValue to ocidModDate's intValue()
ocidAddTitleDataDict's setValue:(ocidIntValue) forKey:("file-mod-date")
####parent-mod-date
set ocidNow to refMe's NSDate's now
set ocidNowNo to ocidNow's timeIntervalSince1970
set ocidIntValue to ocidNowNo's intValue
ocidAddTitleDataDict's setValue:(ocidIntValue) forKey:("parent-mod-date")
####book
set listBookMarkData to (ocidFilePathURL's bookmarkDataWithOptions:(11) includingResourceValuesForKeys:({missing value}) relativeToURL:(missing value) |error|:(reference))
set ocidkDataValue to item 1 of listBookMarkData
(ocidAddTitleDataDict's setObject:(ocidkDataValue) forKey:("book"))
####file-type
# 169 Launchpad とMission Control
# 41 それ以外はまぁ41で間違いなさそう
set ocidIntValue to (refMe's NSNumber's numberWithInteger:41)
(ocidAddTitleDataDict's setValue:(ocidIntValue) forKey:("file-type"))
################################
set ocidAddFileDataDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set coidAbsoluteStringPath to ocidFilePathURL's absoluteString()
(ocidAddFileDataDict's setValue:(coidAbsoluteStringPath) forKey:("_CFURLString"))
####
# 0 /File/Path
# 15 file:// のURL形式
set ocidIntValue to (refMe's NSNumber's numberWithInteger:15)
(ocidAddFileDataDict's setValue:(ocidIntValue) forKey:("_CFURLStringType"))
################################
(ocidAddTitleDataDict's setObject:(ocidAddFileDataDict) forKey:("file-data"))
ocidAddDict's setObject:(ocidAddTitleDataDict) forKey:("tile-data")
################################
####追加データを元のPLISTに戻す
################################
ocidPersistentArray's insertObject:(ocidAddDict) atIndex:(numInsertPosision)

################################
####保存
################################
set boolDone to ocidPlistDict's writeToURL:(ocidPlistPathURL) atomically:true

################################
###CFPreferencesを再起動
################################
#####CFPreferencesを再起動させて変更後の値をロードさせる
try
  set strCommandText to "/usr/bin/killall cfprefsd" as text
  do shell script strCommandText
on error
  set strPlistPath to "/System/Library/LaunchAgents/com.apple.cfprefsd.xpc.agent.plist"
  set strCommandText to ("/bin/launchctl stop -w \"" & strAgentPath & "\"")
  try
    do shell script strCommandText
  end try
  set strCommandText to ("/bin/launchctl start -w \"" & strAgentPath & "\"")
  try
    do shell script strCommandText
end try (*
set strPlistPath to "/System/Library/LaunchDaemons/com.apple.cfprefsd.xpc.daemon.plist"
set strCommandText to ("/bin/launchctl stop -w \"" & strAgentPath & "\"")
try
do shell script strCommandText
end try
set strCommandText to ("/bin/launchctl start -w \"" & strAgentPath & "\"")
try
do shell script strCommandText
end try
*)
end try

set strCommandText to ("/usr/bin/killall Dock")
do shell script strCommandText



|

[persistent-apps]Dockにフォルダやディスクを登録する(改良)

挿入位置の選択をわかりやすくした

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

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

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()
####################################
###ユーザーアプリケーションフォルダ
set ocidURLArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationDirectory) inDomains:(refMe's NSUserDomainMask))
log className() of ocidURLArray as text
set ocidApplicationDirPathURL to ocidURLArray's firstObject()
set aliasDefaultLocation to (ocidApplicationDirPathURL's absoluteURL()) as alias
set ocidLocalizedPathURL to ocidApplicationDirPathURL's URLByAppendingPathComponent:(".localized")
###フォルダなければ作る 488 = 700
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolDone to appFileManager's createDirectoryAtURL:(ocidApplicationDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
###localizedの空ファイルも作る
set ocidLocalizedPath to ocidLocalizedPathURL's |path|()
set listBoolDone to appFileManager's createFileAtPath:(ocidLocalizedPath) |contents|:(missing value) attributes:(ocidAttrDict)
####################################
###ダイアログを前面に出す
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 listUTI to {"com.apple.application-bundle"}
set strPromptText to "フォルダを選んでください" as text
set strPromptMes to "フォルダを選んでください" as text
set aliasFilePath to (choose folder (strPromptMes) with prompt (strPromptText) default location (aliasDefaultLocation) with invisibles without multiple selections allowed and showing package contents) as alias
###追加するパス
set strFilePath to POSIX path of aliasFilePath
set ocidFilePath to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePath's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:true

################################
####Plist読み込み
################################
set ocidURLArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLibraryDirPathURL to ocidURLArray's firstObject()
set ocidPlistPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/com.apple.dock.plist")
####
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
################################
####インサート位置
################################
set ocidPersistentArray to ocidPlistDict's objectForKey:"persistent-apps"
set numCntArray to ocidPersistentArray's |count|() as integer
################################
##作ったけど使わなかったDict
set ocidPersistentDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set listInsertPosision to {} as list
repeat with numNo from 0 to (numCntArray - 1) by 1
  set coidItemDict to (ocidPersistentArray's objectAtIndex:(numNo))
  set strLabel to (coidItemDict's valueForKeyPath:"tile-data.file-label") as text
  set recordAddRec to (run script "return {|" & numNo & "|:\"" & strLabel & "\"} ") as record
(ocidPersistentDict's addEntriesFromDictionary:recordAddRec)
  ##テキストにして
  set strAddList to ("" & numNo & ":" & strLabel & "") as text
  ##リストに追加
  set end of listInsertPosision to strAddList
end repeat
####
log listInsertPosision as list
try
  set listResponse to (choose from list listInsertPosision with title "選んでください" with prompt "挿入位置\r選んだ項目の前に挿入されます" default items (item 1 of listInsertPosision) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
  log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
end if
set strInsertPosision to (item 1 of listResponse) as text
set AppleScript's text item delimiters to ":"
set listItemInsertPosision to every text item of strInsertPosision
set AppleScript's text item delimiters to ""
set numInsertPosision to (item 1 of listItemInsertPosision) as integer

################################
####persistent-appsデータ生成
################################
set ocidAddDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
###GUID実際はランダム番号だがNSFileSystemFileNumberを使う
set listPathAttar to appFileManager's attributesOfItemAtPath:(ocidFilePath) |error|:(reference)
set ocidAttar to item 1 of listPathAttar
set numGUID to ocidAttar's valueForKey:(refMe's NSFileSystemFileNumber)
set ocidIntValue to (refMe's NSNumber's numberWithInteger:(numGUID))
ocidAddDict's setValue:(numGUID) forKey:("GUID")
###
set ocidStringValue to (refMe's NSString's stringWithString:("file-tile"))
ocidAddDict's setValue:(ocidStringValue) forKey:("tile-type")
################################
set ocidAddTitleDataDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
####dock-extra
set ocidBoolValue to (refMe's NSNumber's numberWithBool:false)
ocidAddTitleDataDict's setValue:(ocidBoolValue) forKey:("dock-extra")
####dock-extra
set ocidBoolValue to (refMe's NSNumber's numberWithBool:false)
ocidAddTitleDataDict's setValue:(ocidBoolValue) forKey:("is-beta")
####bundle-identifier
set ocidStringValue to (refMe's NSString's stringWithString:("public.folder"))
ocidAddTitleDataDict's setValue:(ocidStringValue) forKey:("bundle-identifier")
####file-label"
set listAttributesDict to ocidFilePathURL's resourceValuesForKeys:({refMe's NSURLLocalizedNameKey}) |error|:(reference)
set ocidAttributesDict to (item 1 of listAttributesDict)
set ocidLocalizedName to (ocidAttributesDict's objectForKey:(refMe's NSURLLocalizedNameKey))
set ocidFileLabel to (ocidLocalizedName's stringByDeletingPathExtension())
set ocidStringValue to ocidFileLabel's UTF8String()
ocidAddTitleDataDict's setValue:(ocidStringValue) forKey:("file-label")
####file-mod-date
set listAttributesDict to ocidFilePathURL's resourceValuesForKeys:({refMe's NSURLContentModificationDateKey}) |error|:(reference)
set ocidAttributesDict to (item 1 of listAttributesDict)
set ocidModificationDate to (ocidAttributesDict's objectForKey:(refMe's NSURLContentModificationDateKey))
set ocidModDate to ocidModificationDate's timeIntervalSince1970
set ocidIntValue to ocidModDate's intValue()
ocidAddTitleDataDict's setValue:(ocidIntValue) forKey:("file-mod-date")
####parent-mod-date
set ocidNow to refMe's NSDate's now
set ocidNowNo to ocidNow's timeIntervalSince1970
set ocidIntValue to ocidNowNo's intValue
ocidAddTitleDataDict's setValue:(ocidIntValue) forKey:("parent-mod-date")
####book
set listBookMarkData to (ocidFilePathURL's bookmarkDataWithOptions:(11) includingResourceValuesForKeys:({missing value}) relativeToURL:(missing value) |error|:(reference))
set ocidkDataValue to item 1 of listBookMarkData
(ocidAddTitleDataDict's setObject:(ocidkDataValue) forKey:("book"))
####file-type
# 169 Launchpad とMission Control
# 41 それ以外はまぁ41で間違いなさそう
set ocidIntValue to (refMe's NSNumber's numberWithInteger:41)
(ocidAddTitleDataDict's setValue:(ocidIntValue) forKey:("file-type"))
################################
set ocidAddFileDataDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set coidAbsoluteStringPath to ocidFilePathURL's absoluteString()
(ocidAddFileDataDict's setValue:(coidAbsoluteStringPath) forKey:("_CFURLString"))
####
# 0 /File/Path
# 15 file:// のURL形式
set ocidIntValue to (refMe's NSNumber's numberWithInteger:15)
(ocidAddFileDataDict's setValue:(ocidIntValue) forKey:("_CFURLStringType"))
################################
(ocidAddTitleDataDict's setObject:(ocidAddFileDataDict) forKey:("file-data"))
ocidAddDict's setObject:(ocidAddTitleDataDict) forKey:("tile-data")
################################
####追加データを元のPLISTに戻す
################################
ocidPersistentArray's insertObject:(ocidAddDict) atIndex:(numInsertPosision)

################################
####保存
################################
set boolDone to ocidPlistDict's writeToURL:(ocidPlistPathURL) atomically:true

################################
###CFPreferencesを再起動
################################
#####CFPreferencesを再起動させて変更後の値をロードさせる
try
  set strCommandText to "/usr/bin/killall cfprefsd" as text
  do shell script strCommandText
on error
  set strPlistPath to "/System/Library/LaunchAgents/com.apple.cfprefsd.xpc.agent.plist"
  set strCommandText to ("/bin/launchctl stop -w \"" & strAgentPath & "\"")
  try
    do shell script strCommandText
  end try
  set strCommandText to ("/bin/launchctl start -w \"" & strAgentPath & "\"")
  try
    do shell script strCommandText
end try (*
set strPlistPath to "/System/Library/LaunchDaemons/com.apple.cfprefsd.xpc.daemon.plist"
set strCommandText to ("/bin/launchctl stop -w \"" & strAgentPath & "\"")
try
do shell script strCommandText
end try
set strCommandText to ("/bin/launchctl start -w \"" & strAgentPath & "\"")
try
do shell script strCommandText
end try
*)
end try

set strCommandText to ("/usr/bin/killall Dock")
do shell script strCommandText



|

その他のカテゴリー

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