AppleScript Chrome

[com.google.Chrome]全てのウィンドウの全てのタプのURLを取得する


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
----+----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


###アプリケーションのバンドルID
set strBundleID to "com.google.Chrome"
###エラー処理
tell application id strBundleID
  set numWindow to (count of every window) as integer
end tell
if numWindow = 0 then
return "Windowが無いので処理できません"
end if
##戻り値用
set listGetUrl to {} as list

###ダイアログの用意
set ocidAppPathURL to doGetAppPathURL(strBundleID)
set ocidIconFilePathURL to doGetIconPathURL(ocidAppPathURL)
set aliasIconFilePath to (ocidIconFilePathURL's absoluteURL()) as alias
###URLとタイトルを取得
tell application "Google Chrome"
  set listWindowID to id of every window
  repeat with itemWindowID in listWindowID
    tell window id itemWindowID
      set listTabID to (id of every tab)
      repeat with itemTabID in listTabID
        tell tab id itemTabID
          set strURL to URL as text
          set end of listGetUrl to strURL
        end tell
      end repeat
    end tell
  end repeat
end tell

log listGetUrl
##リストを改行区切りテキストに変換
set ocidURLArray to refMe's NSArray's alloc()'s initWithArray:(listGetUrl)
set ocidURLstr to ocidURLArray's componentsJoinedByString:("\n")
set strUrlText to ocidURLstr as text

########################
## ダイアログ
########################
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 strTITLE to ("URLリストです") as text
set strMessage to ("URLリストです") as text
try
  set recordResponse to (display dialog strMessage with title strTITLE default answer strUrlText buttons {"OK", "キャンセル", "クリップボードにコピー"} default button "クリップボードにコピー" cancel button "キャンセル" with icon aliasIconFilePath giving up after 20 without hidden answer) as record
on error strErrorMes number numErrorNO
log strErrorMes
log numErrorNO
return (missing value)
end try
if true is equal to (gave up of recordResponse) then
return "時間切れですやりなおしてください"
else if false is equal to (recordResponse) then
log "キャンセルしました"
return "キャンセルしました"
else if "クリップボードにコピー" is equal to (button returned of recordResponse) then
  try
    set strResponse to (text returned of recordResponse) as text
    ####ペーストボード宣言
    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
    set ocidText to (refMe's NSString's stringWithString:(strResponse))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
  on error
    tell application "Finder"
      set the clipboard to strResponse as text
    end tell
  end try
else
log "キャンセルしました"
return (missing value)
end if

################################
## %エンコードをデコード
################################
on doUrlDecode(argText)
  ##テキスト
  set ocidArgText to refMe's NSString's stringWithString:(argText)
  ##デコード
  set ocidArgTextEncoded to ocidArgText's stringByRemovingPercentEncoding
  set strArgTextEncoded to ocidArgTextEncoded as text
return strArgTextEncoded
end doUrlDecode


########################
## bundle to AppPathURL
########################
to doGetAppPathURL(argBundleiD)
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  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
  if ocidAppPathURL = (missing value) then
    tell application "Finder"
      try
        set aliasAppApth to (application file id strBundleID) as alias
      on error
log "アプリケーションが見つかりませんでした"
return (missing value)
      end try
    end tell
    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:(ocidFilePath) isDirectory:true
  end if
return ocidAppPathURL
end doGetAppPathURL


########################
## AppPathURL to AppIcon
########################
to doGetIconPathURL(argAppPathURL)
  ###アイコン名をPLISTから取得
  set ocidPlistPathURL to argAppPathURL's URLByAppendingPathComponent:("Contents/Info.plist") isDirectory:false
  set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
  set strIconFileName to (ocidPlistDict's valueForKey:("CFBundleIconFile")) as text
  ###ICONのURLにして
  set strPath to ("Contents/Resources/" & strIconFileName) as text
  set ocidIconFilePathURL to argAppPathURL's URLByAppendingPathComponent:(strPath) isDirectory:false
  ###拡張子の有無チェック
  set strExtensionName to (ocidIconFilePathURL's pathExtension()) as text
  if strExtensionName is "" then
    set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:"icns"
  end if
  ###ICONファイルが実際にあるか?チェック
  set appFileManager to refMe's NSFileManager's defaultManager()
  set boolExists to appFileManager's fileExistsAtPath:(ocidIconFilePathURL's |path|)
  ###ICONがみつかない時用にデフォルトを用意する
  if boolExists is false then
    set strIconPath to "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
    set ocidIconPathStr to refMe's NSString's stringWithString:(strIconPath)
    set ocidIconPath to ocidIconPathStr's stringByStandardizingPath()
    set ocidIconFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidIconPath) isDirectory:false)
  else
return ocidIconFilePathURL
  end if
end doGetIconPathURL

|

google chrome バージョンチェッカー


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

#!/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 strBundleID to "com.google.Chrome" as text
set strLocation to ("https://dl.google.com/dl/chrome/mac/universal/stable/gcea/googlechrome.dmg")

#################################
### element & node
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:("request")
set ocidNode to refMe's NSXMLNode's attributeWithName:("protocol") stringValue:("3.0")
ocidRootElement's addAttribute:(ocidNode)
set ocidNode to refMe's NSXMLNode's attributeWithName:("ismachine") stringValue:("1")
ocidRootElement's addAttribute:(ocidNode)
##
set ocidOsElement to refMe's NSXMLElement's elementWithName:("os")
set ocidNode to refMe's NSXMLNode's attributeWithName:("platform") stringValue:("mac")
ocidOsElement's addAttribute:(ocidNode)
set ocidNode to refMe's NSXMLNode's attributeWithName:("os_version") stringValue:("14.0")
ocidOsElement's addAttribute:(ocidNode)
set ocidNode to refMe's NSXMLNode's attributeWithName:("version") stringValue:("14.0")
ocidOsElement's addAttribute:(ocidNode)
set ocidNode to refMe's NSXMLNode's attributeWithName:("arch") stringValue:("arm")
ocidOsElement's addAttribute:(ocidNode)
##
set ocidAppElement to refMe's NSXMLElement's elementWithName:("app")
set ocidNode to refMe's NSXMLNode's attributeWithName:("appid") stringValue:(strBundleID)
ocidAppElement's addAttribute:(ocidNode)
set ocidNode to refMe's NSXMLNode's attributeWithName:("brand") stringValue:("gcea")
ocidAppElement's addAttribute:(ocidNode)
##
set ocidUpdateCheckElement to (refMe's NSXMLElement's elementWithName:("updatecheck"))
ocidAppElement's insertChild:(ocidUpdateCheckElement) atIndex:0
##
ocidRootElement's addChild:(ocidOsElement)
ocidRootElement's addChild:(ocidAppElement)

#################################
###NSXMLDocument を生成する
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"

set ocidSaveStrings to ocidOutPutXML's XMLString()
set strOutPutXML to ocidSaveStrings as text

#################################
##XML内のクオテーションをエスケープ
set strXML4Command to doReplace(strOutPutXML, "\"", "\\\"")
##コマンド整形
set strCommandText to ("/usr/bin/curl -X POST -d \"" & strXML4Command & "\" https://tools.google.com/service/update2") as text
log strCommandText
##コマンド実行
set strResponseXML to (do shell script strCommandText) as text

#################################
##戻り値XML
set ocidResponseXML to refMe's NSString's stringWithString:(strResponseXML)
set ocidXMLdata to ocidResponseXML's dataUsingEncoding:(refMe's NSUTF8StringEncoding)
###NSXMLDocument's
set listXMLdoc to refMe's NSXMLDocument's alloc()'s initWithData:(ocidXMLdata) options:(0) |error|:(reference)
set ocidReadXMLDoc to (item 1 of listXMLdoc)
##rootElement
set ocidRootElement to ocidReadXMLDoc's rootElement()
set listManifest to ocidRootElement's nodesForXPath:("//response/app/updatecheck/manifest") |error|:(reference)
##NSXMLElement
set ocidManifest to (item 1 of listManifest)'s firstObject()
set strNewVersion to (ocidManifest's attributeForName:("version"))'s stringValue() as text


################################
###バンドルIDからアプリケーションのインストール先を求める
set ocidAppBundle to refMe's NSBundle's bundleWithIdentifier:(strBundleID)
if ocidAppBundle is missing value then
  set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()
  set ocidAppBundlePathURL to (appNSWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID))
else
  set ocidAppBundleStr to ocidAppBundle's bundlePath()
  set ocidAppBundlePath to ocidAppBundleStr's stringByStandardizingPath
  set ocidAppBundlePathURL to (refMe's NSURL's fileURLWithPath:(ocidAppBundlePath))
end if
if ocidAppBundlePathURL = (missing value) then
  tell application "Finder"
    try
      set aliasAppApth to (application file id strBundleID) as alias
    on error
return "アプリケーションが見つかりませんでした"
    end try
  end tell
  set strAppPath to POSIX path of aliasAppApth as text
  set ocidAppBundlePathStr to refMe's NSString's stringWithString:(strAppPath)
  set ocidAppBundlePath to ocidAppBundlePathStr's stringByStandardizingPath()
  set ocidAppBundlePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidAppBundlePath) isDirectory:true
end if
###コマンドのあるディレクトリ
set ocidPlistPathURL to ocidAppBundlePathURL's URLByAppendingPathComponent:("Contents/Info.plist")
#####PLISTの内容を読み込んで
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set listReadPlistData to refMe's NSMutableDictionary's dictionaryWithContentsOfURL:(ocidPlistPathURL) |error|:(reference)
set ocidPlistDict to item 1 of listReadPlistData
set strCfbundleversionPlist to (ocidPlistDict's valueForKey:"CFBundleShortVersionString") as text
################################################
######
if strNewVersion is strCfbundleversionPlist then
  set strTitle to ("最新版を利用中です") as text
  set strCom to ("最新版を利用中です\r" & strCfbundleversionPlist) as text
  set strMes to strCom
else
  set strTitle to ("アップデートがあります:" & strNewVersion) as text
  set strCom to ("アップデートがあります\r最新:" & strNewVersion & "\r使用中:" & strCfbundleversionPlist) as text
  set strMes to strCom
end if
################################################
###### ダイアログ
################################################
set appFileManager to refMe's NSFileManager's defaultManager()

####ダイアログに指定アプリのアイコンを表示する
###アイコン名をPLISTから取得
set strIconFileName to (ocidPlistDict's valueForKey:("CFBundleIconFile")) as text
###ICONのURLにして
set strPath to ("Contents/Resources/" & strIconFileName) as text
set ocidIconFilePathURL to ocidAppBundlePathURL's URLByAppendingPathComponent:(strPath) isDirectory:false
###拡張子の有無チェック
set strExtensionName to (ocidIconFilePathURL's pathExtension()) as text
if strExtensionName is "" then
  set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:"icns"
end if
##-->これがアイコンパス
log ocidIconFilePathURL's absoluteString() as text
###ICONファイルが実際にあるか?チェック
set boolExists to appFileManager's fileExistsAtPath:(ocidIconFilePathURL's |path|)
###ICONがみつかない時用にデフォルトを用意する
if boolExists is false then
  set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
else
  set aliasIconPath to ocidIconFilePathURL's absoluteURL() as alias
  set strIconPath to ocidIconFilePathURL's |path|() as text
end if

set recordResult to (display dialog strCom with title strTitle default answer strMes buttons {"クリップボードにコピー", "終了", "ダウンロード"} default button "ダウンロード" cancel button "終了" giving up after 20 with icon aliasIconPath without hidden answer)

if button returned of recordResult is "ダウンロード" then
  tell application "Finder"
    open location strLocation
  end tell
end if
if button returned of recordResult is "クリップボードにコピー" then
  try
    set strText to text returned of recordResult as text
    ####ペーストボード宣言
    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
    set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
  on error
    tell application "Finder"
      set the clipboard to strTitle as text
    end tell
  end try
end if


#################################
##クオテーションの置換用
to doReplace(argOrignalText, argSearchText, argReplaceText)
  set strDelim to AppleScript's text item delimiters
  set AppleScript's text item delimiters to argSearchText
  set listDelim to every text item of argOrignalText
  set AppleScript's text item delimiters to argReplaceText
  set strReturn to listDelim as text
  set AppleScript's text item delimiters to strDelim
return strReturn
end doReplace


|

OpenChromeURLs


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

#!/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 listURLs to {"chrome-urls", "about", "accessibility", "app-service-internals", "app-settings", "apps", "attribution-internals", "autofill-internals", "blob-internals", "bluetooth-internals", "bookmarks", "commerce-internals", "components", "connectors-internals", "crashes", "credits", "device-log", "dino", "discards", "download-internals", "downloads", "extensions", "extensions-internals", "family-link-user-internals", "flags", "gcm-internals", "gpu", "help", "histograms", "history", "history-clusters-internals", "indexeddb-internals", "inspect", "interstitials", "invalidations", "local-state", "management", "media-engagement", "media-internals", "metrics-internals", "net-export", "net-internals", "network-errors", "new-tab-page", "new-tab-page-third-party", "newtab", "ntp-tiles-internals", "omnibox", "optimization-guide-internals", "password-manager", "password-manager-internals", "policy", "predictors", "prefs-internals", "print", "private-aggregation-internals", "process-internals", "profile-internals", "quota-internals", "safe-browsing", "serviceworker-internals", "settings", "signin-internals", "site-engagement", "suggest-internals", "sync-internals", "system", "tab-search.top-chrome", "terms", "topics-internals", "tracing", "translate-internals", "ukm", "usb-internals", "user-actions", "version", "web-app-internals", "webrtc-internals", "webrtc-logs", "whats-new"} 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 strTitle to "選んでください" as text
set strPrompt to "選んでください" as text
try
  set listResponse to (choose from list listURLs with title strTitle with prompt strPrompt default items (item 1 of listURLs) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed) as list
on error
  log "エラーしました"
return "エラーしました"
  error "エラーしました" number -200
end try
if listResponse = {} then
  log "何も選択していない"
return "何も選択していない"
else if (item 1 of listResponse) is false then
return "キャンセルしました"
  error "キャンセルしました" number -200
else
  ##############################
  ###選択されたホスト名を順番に開く
  repeat with itemResponse in listResponse
    ###テキストに確定
    set strResponse to itemResponse as text
    ###URLコンポーネント初期化
    set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
    ###スキーム を追加
(ocidURLComponents's setScheme:("chrome"))
    ###パスを追加(setPathじゃないよ)
(ocidURLComponents's setHost:(strResponse))
    set ocidTagURL to ocidURLComponents's |URL|
    set strTagURL to ocidTagURL's absoluteString() as text
    tell application "Google Chrome"
      activate
      tell window 1
set objNewTab to make new tab
tell objNewTab to set URL to strTagURL
      end tell
    end tell
    
  end repeat
end if



|

選択範囲を『引用』としてTwitterへ投稿する


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

#!/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

set strBundleID to "com.google.Chrome" as text

property refMe : a reference to current application

####ペーストボード初期化
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
appPasteboard's clearContents()

#####WINDOWチェック
tell application id strBundleID
  set numCntWindow to (count of every window) as integer
  if numCntWindow = 0 then
return "ウィンドウがありません"
  end if
end tell
#####
tell application "Google Chrome"
  tell front window
    tell active tab
      activate
      copy selection
    end tell
  end tell
end tell
###ペーストボード格納待ち
delay 0.1
####ペーストボード取得
set ocidPastBoardTypeArray to appPasteboard's types()
log ocidPastBoardTypeArray as list
if (count of ocidPastBoardTypeArray) = 0 then
  display alert "選択範囲がありませんでした"
return "選択範囲がありませんでした"
end if
if (ocidPastBoardTypeArray as list) contains "NSStringPboardType" then
  ###ペーストボードの中身をテキストで確定
  set ocidSelectionText to appPasteboard's stringForType:(refMe's NSStringPboardType)
else if (ocidPastBoardTypeArray as list) contains "public.utf8-plain-text" then
  set ocidSelectionText to appPasteboard's stringForType:("public.utf8-plain-text")
end if
set boolSuffix to ocidSelectionText's hasSuffix:("\n")
if boolSuffix = true then
  set numTextLengh to (ocidSelectionText's |length|()) as integer
  set ocidSelectionText to ocidSelectionText's substringToIndex:(numTextLengh - 1)
end if
set boolSuffix to ocidSelectionText's hasSuffix:("\n")
if boolSuffix = true then
  set numTextLengh to (ocidSelectionText's |length|()) as integer
  set ocidSelectionText to ocidSelectionText's substringToIndex:(numTextLengh - 1)
end if

set strSelectionText to ocidSelectionText as text
set strSelectionText to ("❝" & strSelectionText & "❞") as text

########################
tell application "Google Chrome"
  activate
  tell front window
    tell active tab
      set strURL to URL as text
      set strName to title as text
    end tell
  end tell
end tell

####################
###
set ocidTitleString to refMe's NSString's stringWithString:(strName)
set numTitleLengh to ocidTitleString's |length|() as integer
if numTitleLengh > 52 then
  set ocidRange to refMe's NSMakeRange(0, 50)
  set ocidTitle to ocidTitleString's substringWithRange:(ocidRange)
  set strTitle to ((ocidTitle as text) & "…") as text
else
  set ocidRange to refMe's NSMakeRange(0, numTitleLengh)
  set ocidTitle to ocidTitleString's substringWithRange:(ocidRange)
  set strTitle to ocidTitle as text
end if

####################
###ホスト名
set ocidURLString to refMe's NSString's stringWithString:(strURL)
set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString)
set strURL to ocidURL's absoluteString() as text
set strHostName to ocidURL's |host|() as text
set ocidComponents to refMe's NSURLComponents's componentsWithURL:(ocidURL) resolvingAgainstBaseURL:(true)
ocidComponents's setQuery:(missing value)
ocidComponents's setFragment:(missing value)
set strURL to ocidComponents's |URL|'s absoluteString() as text



####################
set ocidDate to refMe's NSDate's now()
###日付
set ocidFormatter to refMe's NSDateFormatter's alloc()'s init()
set ocidLocale to refMe's NSLocale's currentLocale
ocidFormatter's setLocale:(ocidLocale)
###時間表示無し
ocidFormatter's setTimeStyle:(refMe's NSDateFormatterNoStyle)
ocidFormatter's setDateStyle:(refMe's NSDateFormatterLongStyle)
set ocidDateString to ocidFormatter's stringFromDate:(ocidDate)
set strDateString to ocidDateString as text

set strQuoteText to ("\n--\n" & strSelectionText & "\r" & strTitle & "\r" & strURL & "\r引用元:[" & strHostName & "] アクセス日:" & strDateString) as text

###エンコードして
set strCurrentTabUrl to doUrlEncode(strURL) as text
set strCurrentTabTitle to doUrlEncode(strQuoteText) as text
###送信用URLに整形して
set strBaseUrl to "https://twitter.com/intent/tweet?" as text
set strOpenUrl to ("" & strBaseUrl & "url=" & strCurrentTabUrl & "&text=" & strCurrentTabTitle & "") as text
###Chromeに渡す
tell application "Google Chrome"
  activate
  tell window 1
    set objNewTab to make new tab
    tell objNewTab to set URL to strOpenUrl
  end tell
end tell
####################################
###### %エンコード
####################################
on doUrlEncode(argText)
  ##テキスト
  set ocidArgText to refMe's NSString's stringWithString:(argText)
  ##キャラクタセットを指定
  set ocidChrSet to refMe's NSCharacterSet's URLQueryAllowedCharacterSet
  ##キャラクタセットで変換
  set ocidArgTextEncoded to ocidArgText's stringByAddingPercentEncodingWithAllowedCharacters:(ocidChrSet)
  ######## 置換 %エンコードの追加処理
  ###置換レコード
  set recordPercentMap to {|+|:"%2B", |=|:"%3D", |&|:"%26", |$|:"%24"} as record
  ###ディクショナリにして
  set ocidPercentMap to refMe's NSDictionary's alloc()'s initWithDictionary:(recordPercentMap)
  ###キーの一覧を取り出します
  set ocidAllKeys to ocidPercentMap's allKeys()
  ###取り出したキー一覧を順番に処理
  repeat with itemAllKey in ocidAllKeys
    ##キーの値を取り出して
    set ocidMapValue to (ocidPercentMap's valueForKey:(itemAllKey))
    ##置換
    set ocidEncodedText to (ocidArgTextEncoded's stringByReplacingOccurrencesOfString:(itemAllKey) withString:(ocidMapValue))
    ##次の変換に備える
    set ocidArgTextEncoded to ocidEncodedText
  end repeat
  ##テキスト形式に確定
  set strTextToEncode to ocidEncodedText as text
  ###値を戻す
return strTextToEncode
end doUrlEncode


|

[Chrome]Twitterへ投稿


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

#!/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 scripting additions

property refMe : a reference to current application

tell application "Google Chrome"
  activate
  tell front window
    tell active tab
      set strCurrentTabUrl to URL as text
      set strCurrentTabTitle to title as text
    end tell
  end tell
end tell

###区切り文字を入れて改行
set strCurrentTabTitle to ("\n--\n" & strCurrentTabTitle) as text
###エンコードして
set strCurrentTabUrl to doUrlEncode(strCurrentTabUrl) as text
set strCurrentTabTitle to doUrlEncode(strCurrentTabTitle) as text
###送信用URLに整形して
set strBaseUrl to "https://twitter.com/intent/tweet?" as text
set strOpenUrl to ("" & strBaseUrl & "url=" & strCurrentTabUrl & "&text=" & strCurrentTabTitle & "") as text
###Chromeに渡す
tell application "Google Chrome"
  activate
  tell window 1
    set objNewTab to make new tab
    tell objNewTab to set URL to strOpenUrl
  end tell
end tell
####################################
###### %エンコード
####################################
on doUrlEncode(argText)
  ##テキスト
  set ocidArgText to refMe's NSString's stringWithString:(argText)
  ##キャラクタセットを指定
  set ocidChrSet to refMe's NSCharacterSet's URLQueryAllowedCharacterSet
  ##キャラクタセットで変換
  set ocidArgTextEncoded to ocidArgText's stringByAddingPercentEncodingWithAllowedCharacters:(ocidChrSet)
  ######## 置換 %エンコードの追加処理
  ###置換レコード
  set recordPercentMap to {|+|:"%2B", |=|:"%3D", |&|:"%26", |$|:"%24"} as record
  ###ディクショナリにして
  set ocidPercentMap to refMe's NSDictionary's alloc()'s initWithDictionary:(recordPercentMap)
  ###キーの一覧を取り出します
  set ocidAllKeys to ocidPercentMap's allKeys()
  ###取り出したキー一覧を順番に処理
  repeat with itemAllKey in ocidAllKeys
    ##キーの値を取り出して
    set ocidMapValue to (ocidPercentMap's valueForKey:(itemAllKey))
    ##置換
    set ocidEncodedText to (ocidArgTextEncoded's stringByReplacingOccurrencesOfString:(itemAllKey) withString:(ocidMapValue))
    ##次の変換に備える
    set ocidArgTextEncoded to ocidEncodedText
  end repeat
  ##テキスト形式に確定
  set strTextToEncode to ocidEncodedText as text
  ###値を戻す
return strTextToEncode
end doUrlEncode

|

%エンコードされたURLを読めるURLに戻す

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

tell application "Google Chrome"
  activate
  tell front window
    tell active tab
set strURL to URL as text
set strName to title as text
    end tell
  end tell
end tell

set strLineText to urlEncode(strURL)

###URLをクリップボードに戻す
tell application "Finder"
  set the clipboard to strLineText as string
end tell

on urlEncode(argText)
  ##テキスト
  set ocidArgText to refMe's NSString's stringWithString:(argText)
  ##デコード
  set ocidArgTextEncoded to ocidArgText's stringByRemovingPercentEncoding
  set strArgTextEncoded to ocidArgTextEncoded as text
return strArgTextEncoded
end urlEncode

|

[Google Chrome]表示中のページのHTMLリンクを作成する(BLOG用)

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

###置換レコード
set recordEntityMap to {|&|:"&amp;", |<|:"&lt;", |>|:"&gt;", |"|:"&quot;", |'|:"&apos;", |=|:"&#x3D;", |+|:"&#x2B;"} as record
###ディクショナリにして
set ocidEntityMap to refMe's NSDictionary's alloc()'s initWithDictionary:recordEntityMap
###キーの一覧を取り出します
set ocidAllKeys to ocidEntityMap's allKeys()


tell application "Google Chrome"
  activate
  tell front window
    tell active tab
set strURL to URL as text
set strName to title as text
    end tell
  end tell
end tell

###タイトルをHTMLエンティティ化する
###選択中テキスト
set ocidSelectedText to refMe's NSString's stringWithString:strName
###可変テキストにして
set ocidTextToEncode to refMe's NSMutableString's alloc()'s initWithCapacity:0
ocidTextToEncode's setString:ocidSelectedText
###取り出したキー一覧を順番に処理
repeat with itemAllKey in ocidAllKeys
  ##キーの値を取り出して
  set ocidMapValue to (ocidEntityMap's valueForKey:itemAllKey)
  ##置換
  set ocidEncodedText to (ocidTextToEncode's stringByReplacingOccurrencesOfString:(itemAllKey) withString:(ocidMapValue))
  ##次の変換に備える
  set ocidTextToEncode to ocidEncodedText
end repeat
####クラス指定とかはここで  1と4はspan等で囲いたい場合
set theHtmlLine1 to "" as text
set theHtmlLine2 to "<a rel=\"nofollow\" href=\"" & strURL & "\" class=\"\" title=\"" & ocidTextToEncode & "\">" as text
set theHtmlLine3 to "【LINK】" & ocidTextToEncode & "</a>" as text
set theHtmlLine4 to "" as text

set theHtmlLine to (theHtmlLine1 & theHtmlLine2 & theHtmlLine3 & theHtmlLine4) as text

###リンクHTMLをクリップボードに
tell application "Finder"
  set the clipboard to theHtmlLine as string
end tell


|

[spotify]再生中の曲名とアーティスト名で検索

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

#!/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 ocidPasteboard to refMe's NSPasteboard's generalPasteboard()

tell application "Google Chrome"
  activate
  tell front window
    tell active tab
set strCurrentTabUrl to URL as text
set strCurrentTabTitle to title as text
    end tell
  end tell
end tell

log strCurrentTabTitle

if strCurrentTabUrl does not contain "spotify" then
return "spotifyで再生中のタイトルで検索なので中止します"
end if

if strCurrentTabTitle does not contain "•" then
return "spotifyで再生中のタイトルで検索なので中止します"
end if

set AppleScript's text item delimiters to " • "
set listCurrentTabTitle to every text item of strCurrentTabTitle
set AppleScript's text item delimiters to ""

set strSongTitle to (item 1 of listCurrentTabTitle) as text
set strArtistName to (item 2 of listCurrentTabTitle) as text

set strSeachText to ("\"" & strArtistName & "\"+\"" & strSongTitle & "\"") as text
set strText to ("" & strArtistName & "\t" & strSongTitle & "") as text




###可変テキストに格納しておく
set ocidSeachText to refMe's NSString's stringWithString:(strSeachText)
set ocidSeachString to refMe's NSMutableString's alloc()'s initWithCapacity:0
ocidSeachString's setString:ocidSeachText
######## %エンコードする
##キャラクタセットを指定
set ocidChrSet to refMe's NSCharacterSet's URLQueryAllowedCharacterSet
###ペーストボードの内容をキャラクタセットで変換
set ocidSeachStringEnc to ocidSeachString's stringByAddingPercentEncodingWithAllowedCharacters:(ocidChrSet)

######## 置換 %エンコードの追加処理
###置換レコード
set recordPercentMap to {|+|:"%2B", |=|:"%3D", |&|:"%26"} as record
###ディクショナリにして
set ocidPercentMap to refMe's NSDictionary's alloc()'s initWithDictionary:recordPercentMap
###キーの一覧を取り出します
set ocidAllKeys to ocidPercentMap's allKeys()

###取り出したキー一覧を順番に処理
repeat with itemAllKey in ocidAllKeys
  ##キーの値を取り出して
  set ocidMapValue to (ocidPercentMap's valueForKey:itemAllKey)
  ##置換
  set ocidEncodedText to (ocidSeachStringEnc's stringByReplacingOccurrencesOfString:(itemAllKey) withString:(ocidMapValue))
  ##次の変換に備える
  set ocidTextToEncode to ocidEncodedText
end repeat

set strSeachText to ocidTextToEncode as text




set ocidText to refMe's NSString's alloc()'s initWithString:(strText)
ocidPasteboard's setString:ocidText forType:(refMe's NSPasteboardTypeString)

set strBaseUrl to "https://www.google.com/search?q="

set strOpenURL to (strBaseUrl & strSeachText) as text

tell application "Google Chrome"
  set numCntWindow to (count of every window) as integer
  if numCntWindow ≠ 0 then
    tell front window
set objNewTab to make new tab
tell objNewTab to set URL to strOpenURL
    end tell
  else
make new window
    tell front window
set objNewTab to make new tab
tell objNewTab to set URL to strOpenURL
    end tell
    
  end if
end tell


|

[bash]全ローカルユーザーに同じ処理(クロームインストール)

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

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe

########################################
###管理者インストールしているか?チェック
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行したユーザーは:$USER_WHOAMI"
if [ "$USER_WHOAMI" != "root" ]; then
  /bin/echo "このスクリプトを実行するには管理者権限が必要です。"
  /bin/echo "sudo で実行してください"
  exit 1
else
  ###実行しているユーザー名
  SUDO_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
  /bin/echo "実行ユーザー:" "$SUDO_USER"
fi

########################################
###全ユーザーで使う起動時に削除する項目
/bin/mkdir -p "/private/tmp/TemporaryItems/Trash"
LOCAL_TMP_DIR=$(/usr/bin/mktemp -d "/private/tmp/TemporaryItems/XXXXXXXX")
/bin/chmod -Rf 777 "/private/tmp/TemporaryItems"
/bin/echo "LOCAL_TMP_DIR:CURL:" "$LOCAL_TMP_DIR"
### CPUタイプでの分岐
ARCHITEC=$(/usr/bin/arch)
/bin/echo "Running on $ARCHITEC"
if [ "$ARCHITEC" == "arm64" ]; then
  if ! /usr/bin/curl -L -o "$LOCAL_TMP_DIR/googlechrome.dmg" 'https://dl.google.com/dl/chrome/mac/universal/stable/gcea/googlechrome.dmg' --connect-timeout 20; then
    echo "ファイルのダウンロードに失敗しました"
    exit 1
  fi
else
  if ! /usr/bin/curl -L -o "$LOCAL_TMP_DIR/googlechrome.dmg" 'https://dl.google.com/dl/chrome/mac/universal/stable/gcea/googlechrome.dmg' --connect-timeout 20; then
    echo "ファイルのダウンロードに失敗しました"
    exit 1
  fi
fi
##全ユーザー実行可能にしておく
/bin/chmod 755 "$LOCAL_TMP_DIR/googlechrome.dmg"

########################################
###アプリケーションの終了
###コンソールユーザーにのみ処理する
CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
/bin/echo "CONSOLE_USER:$CONSOLE_USER"
if [ -z "$CONSOLE_USER" ]; then
  /bin/echo "コンソールユーザーが無い=電源入れてログインウィンドウ状態"
else
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/osascript -e "tell application id \"com.google.Chrome\" to quit"
fi
/bin/sleep 2
##念の為 KILLもする
/usr/bin/killall "Google Chrome" 2>/dev/null
/usr/bin/killall "Google Chrome Helper" 2>/dev/null

########################################
###ローカルドメインに対しての処理
function DO_MOVE_TO_TRASH_SUDO() {
  if [ -e "$1" ]; then
    TRASH_DIR=$(/usr/bin/mktemp -d "/private/tmp/TemporaryItems/Trash/XXXXXXXX")
    /usr/bin/sudo /bin/chmod 777 "$TRASH_DIR"
    /usr/bin/sudo /bin/mv "$1" "$TRASH_DIR"
  fi
}
DO_MOVE_TO_TRASH_SUDO "/Applications/Google Chrome.app"

DO_MOVE_TO_TRASH_SUDO "/Library/Caches/com.google.SoftwareUpdate.0"
DO_MOVE_TO_TRASH_SUDO "/Library/Caches/com.google.SoftwareUpdate"
##ここはお好みで
DO_MOVE_TO_TRASH_SUDO "/Library/Google"
DO_MOVE_TO_TRASH_SUDO "/Library/Application Support/Google"

DO_MOVE_TO_TRASH_SUDO "/private/tmp/com.google.Keystone"

########################################
#####古いファイルをゴミ箱に LaunchCtl
function DO_MOVE_TO_TRASH_LAUNCHCTL() {
  if [ -e "$1" ]; then
    /usr/bin/sudo /bin/launchctl stop -w "$1"
    /usr/bin/sudo /bin/launchctl unload -w "$1"
    #### bootoutするのか?はお好みで
    /usr/bin/sudo /bin/launchctl bootout "$1"
    TRASH_DIR=$(/usr/bin/mktemp -d "$HOME/.Trash/XXXXXXXX")
    /usr/bin/sudo /bin/chmod 777 "$TRASH_DIR"
    /usr/bin/sudo /bin/mv "$1" "$TRASH_DIR"
  fi
}
DO_MOVE_TO_TRASH_LAUNCHCTL "/Library/LaunchAgents/com.google.keystone.xpcservice.plist"
DO_MOVE_TO_TRASH_LAUNCHCTL "/Library/LaunchAgents/com.google.keystone.agent.plist"
DO_MOVE_TO_TRASH_LAUNCHCTL "/Library/LaunchDaemons/com.google.keystone.daemon.plist"

########################################
###ローカルのユーザーアカウントを取得
TEXT_RESULT=$(/usr/bin/dscl localhost -list /Local/Default/Users PrimaryGroupID | /usr/bin/awk '$2 == 20 { print $1 }')

###リストにする
read -d '\\n' -r -a LIST_USER <<<"$TEXT_RESULT"

###リスト内の項目数
NUM_CNT=${#LIST_USER[@]}
/bin/echo "ユーザー数:" "$NUM_CNT"
########################################
##リストの内容を順番に処理
for ITEM_LIST in "${LIST_USER[@]}"; do
  /bin/echo "LIST_USER:MKDIR:" "${ITEM_LIST}"
  ##ライブラリの不可視属性を解除
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/chflags nohidden /Users/"${ITEM_LIST}"/Library
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/SetFile -a v /Users/"${ITEM_LIST}"/Library
  ##ユーザーアプリケーションフォルダを作る
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p /Users/"${ITEM_LIST}"/Applications
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 /Users/"${ITEM_LIST}"/Applications
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/sbin/chown "${ITEM_LIST}" /Users/"${ITEM_LIST}"/Applications
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch /Users/"${ITEM_LIST}"/Applications/.localized
  ##ユーザーユーティリティフォルダを作る
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p /Users/"${ITEM_LIST}"/Applications/Utilities
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 755 /Users/"${ITEM_LIST}"/Applications/Utilities
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/sbin/chown "${ITEM_LIST}" /Users/"${ITEM_LIST}"/Applications/Utilities
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch /Users/"${ITEM_LIST}"/Applications/Utilities/.localized
  ## Managed Itemsフォルダを作る
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "/Users/${ITEM_LIST}/Library/Managed Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 755 "/Users/${ITEM_LIST}/Library/Managed Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/sbin/chown "${ITEM_LIST}" "/Users/${ITEM_LIST}/Library/Managed Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "/Users/${ITEM_LIST}//Library/Managed Items/.localized"
  ##アクセス権チェック
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 /Users/"${ITEM_LIST}"/Library
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 /Users/"${ITEM_LIST}"/Movies
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 /Users/"${ITEM_LIST}"/Music
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 /Users/"${ITEM_LIST}"/Pictures
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 /Users/"${ITEM_LIST}"/Downloads
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 /Users/"${ITEM_LIST}"/Documents
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 /Users/"${ITEM_LIST}"/Desktop
  ##全ローカルユーザーに対して実施したい処理があれば追加する

done

for ITEM_LIST in "${LIST_USER[@]}"; do
  /bin/echo "LIST_USER:CLEAR:" "${ITEM_LIST}"
  #####古いファイルをゴミ箱に  USER
  function DO_MOVE_TO_TRASH() {
    if [ -e "$1" ]; then
      TRASH_DIR=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/mktemp -d "/Users/${ITEM_LIST}/.Trash/XXXXXXXX")
      /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 777 "$TRASH_DIR"
      /usr/bin/sudo -u "${ITEM_LIST}" /bin/mv "$1" "$TRASH_DIR"
    fi
  }
  #####古いファイルをゴミ箱に
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Applications/Google Chrome.app"

  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Application Support/Google/GoogleUpdater"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Application Support/Google/Chrome/GrShaderCache"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Application Support/Google/Chrome/Guest Profile"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Application Support/Google/Chrome/ShaderCache"

  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Caches/com.google.Keystone"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Caches/com.google.SoftwareUpdate"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Caches/Google/Chrome"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Google"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/HTTPStorages/com.google.Keystone"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Receipts/com.google.Chrome.bom"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Receipts/com.google.Chrome.plist"

  ###############/var/folde TemporaryDirectory
  MKTEMP_DIR=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/mktemp -d)
  TEMP_DIR_T="$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/dirname "$MKTEMP_DIR")"
  function DO_MOVE_TO_TRASH_T() {
    if [ -e "$1" ]; then
      TRASH_DIR=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/mktemp -d "/Users/${ITEM_LIST}/.Trash/XXXXXXXX")
      /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 777 "$TRASH_DIR"
      /usr/bin/sudo -u "${ITEM_LIST}" /bin/mv "$1" "$TRASH_DIR"
    fi
  }
  #####古いファイルをゴミ箱に
  DO_MOVE_TO_TRASH_T "$TEMP_DIR_T/Google Chrome"
  DO_MOVE_TO_TRASH_T "$TEMP_DIR_T/Google Chrome Helper"
  DO_MOVE_TO_TRASH_T "$TEMP_DIR_T/Google Chrome Helper (GPU)"
  DO_MOVE_TO_TRASH_T "$TEMP_DIR_T/Google Chrome Helper (Renderer)"

  TEMP_DIR="$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/dirname "$TEMP_DIR_T")"
  TEMP_DIR_C="${TEMP_DIR}/C"

  function DO_MOVE_TO_TRASH_C() {
    if [ -e "$1" ]; then
      TRASH_DIR=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/mktemp -d "/Users/${ITEM_LIST}/.Trash/XXXXXXXX")
      /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 777 "$TRASH_DIR"
      /usr/bin/sudo -u "${ITEM_LIST}" /bin/mv "$1" "$TRASH_DIR"
    fi
  }
  #####古いファイルをゴミ箱に
  DO_MOVE_TO_TRASH_C "$TEMP_DIR_C/com.google.Chrome"
  DO_MOVE_TO_TRASH_C "$TEMP_DIR_C/com.google.Chrome.Helper"
  DO_MOVE_TO_TRASH_C "$TEMP_DIR_C/com.google.Chrome.Helper-(GPU)"
  DO_MOVE_TO_TRASH_C "$TEMP_DIR_C/com.google.Chrome.Helper-(Renderer)"
done

for ITEM_LIST in "${LIST_USER[@]}"; do
  /bin/echo "LIST_USER:LUNCHAGT:" "${ITEM_LIST}"
  function DO_MOVE_TO_TRASH_LAUNCHAGENT() {
    if [ -e "$1" ]; then
      /usr/bin/sudo -u "${ITEM_LIST}" /bin/launchctl stop -w "$1"
      /usr/bin/sudo -u "${ITEM_LIST}" /bin/launchctl unload -w "$1"
      ###bootoutはお好みで
      /usr/bin/sudo -u "${ITEM_LIST}" /bin/launchctl bootout "$1"
      TRASH_DIR=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/mktemp -d "$HOME/.Trash/XXXXXXXX")
      /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 777 "$TRASH_DIR"
      /usr/bin/sudo -u "${ITEM_LIST}" /bin/mv "$1" "$TRASH_DIR"
    fi
  }
    ####LaunchAgents 停止 削除
  DO_MOVE_TO_TRASH_LAUNCHAGENT "/Users/${ITEM_LIST}/Library/LaunchAgents/com.google.keystone.agent.plist"
  DO_MOVE_TO_TRASH_LAUNCHAGENT "/Users/${ITEM_LIST}/Library/LaunchAgents/com.google.keystone.xpcservice.plist"

done

for ITEM_LIST in "${LIST_USER[@]}"; do
  /bin/echo "LIST_USER:DITTO:" "${ITEM_LIST}"

/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/hdiutil attach  "$LOCAL_TMP_DIR/googlechrome.dmg" -noverify -nobrowse -noautoopen
sleep 2
/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/ditto "/Volumes/Google Chrome/Google Chrome.app"  "/Users/${ITEM_LIST}/Applications/Google Chrome.app"
sleep 2
/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/hdiutil detach /Volumes/Google Chrome -force

done

for ITEM_LIST in "${LIST_USER[@]}"; do
  /bin/echo "LIST_USER:DOCK" "${ITEM_LIST}"
  PLIST_DICT="<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Users/${ITEM_LIST}/Applications/Google Chrome.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/defaults write com.apple.dock persistent-apps -array-add "$PLIST_DICT"
done

###Dock 再起動
/usr/bin/killall Dock

/bin/echo "処理終了しました"

exit 0

|

[memo]GoogleChrome.pkgのユーザーインストール

/usr/sbin/installer -pkg /path/to/GoogleChrome.pkg  -target CurrentUserHomeDirectory -dumplog -allowUntrusted -lang ja
実行時のエラー installer[27230] : Install failed: エラーによってインストールできませんでした。ソフトウェアの製造元に問い合わせてください。 installer: The upgrade failed. (エラーによってインストールできませんでした。ソフトウェアの製造元に問い合わせてください。 パッケージ“GoogleChrome.pkg”からスクリプトを実行中にエラーが起きました。)

原因
ローカルディレクトリに
/Library/Google
/Library/Application Support/Google
/Library/LaunchAgents/com.google.keystone.*
/Library/LaunchDaemons/com.google.keystone*
といった
keystone関連をインストール出来ないため
ローカルユーザーインストールなら『あまり』に気にしなくても良いと思うけど

|

その他のカテゴリー

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