AppleScript

新規AppleScriptファイルを作成する


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

#!/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 ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDownloadsDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDownloadsDirPathURL's absoluteURL()) as alias
##################
###ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set strDefaultFileName to "お好きな名前で.applescript" as text
set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ファイル名 ダイアログ
try
  set aliasSaveFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultFileName with prompt strPromptText) as «class furl»
on error
return "キャンセルしました"
end try
##################
###パス
set strSaveFilePath to (POSIX path of aliasSaveFilePath) as text
set ocidSaveFilePathStr to refMe's NSString's stringWithString:(strSaveFilePath)
set ocidSaveFilePath to ocidSaveFilePathStr's stringByStandardizingPath()
set ocidSaveFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidSaveFilePath) isDirectory:false)

##################
###コンテンツ ここにスクリプトの内容を記述
### "のエスケープと改行 タブ等を\n\t等に置換する事
set strSaveData to ("return (current date) as date") as text
set ocidSaveData to refMe's NSString's stringWithString:(strSaveData)
##################
###保存
set listDone to ocidSaveData's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
return

|

パスワード生成v2


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

#!/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
###ダイアログを前に
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 aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/LockedIcon.icns"
set strMes to ("桁数指定してください")
set numDeg to (13) as integer
set recordResult to (display dialog strMes with title "入力してください" default answer numDeg buttons {"キャンセル", "記号あり", "記号なし"} default button "記号あり" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)

set strText to text returned of recordResult as text
###不要な文字の除去
set ocidResponseText to (refMe's NSString's stringWithString:(strText))
###タブと改行を除去しておく
set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidTextM's appendString:(ocidResponseText)
##改行除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
##タブ除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
####戻り値を半角にする
set ocidNSStringTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
set ocidTextM to (ocidTextM's stringByApplyingTransform:ocidNSStringTransform |reverse|:false)
###数字以外の値を取る
set ocidDecSet to refMe's NSCharacterSet's decimalDigitCharacterSet
set ocidCharSet to ocidDecSet's invertedSet()
set ocidCharArray to ocidTextM's componentsSeparatedByCharactersInSet:(ocidCharSet)
set numInteger to (ocidCharArray's componentsJoinedByString:"") as integer
###4文字以下はここで止める
if numInteger < 4 then
return "4文字以下はパスワードとは言いません"
end if

set numSetA to (round of (numInteger / 4) rounding up) as integer
set numTmp3 to numInteger - numSetA as integer
set numSetB to (round of (numTmp3 / 3) rounding down) as integer
set numTmp2 to numTmp3 - numSetB as integer
set numSetC to (round of (numTmp2 / 2) rounding down) as integer
set numSetD to numTmp2 - numSetC as integer

###ボタンによる分岐
if button returned of recordResult is "記号なし" then
  
  # set strCharSetA to "abcdefghijklmnopqrstuvwxyz"
  ##loijを使わないパターン
  set strCharSetA to "abcdefghkmnpqrstuvwxyz"
  # set strCharSetB to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  ##Oとiを使わないパターン
  set strCharSetB to "ABCDEFGHJKLMNPQRSTUVWXYZ"
  set strCharSetC to "0123456789"
  set strCharSetD to "abcdefghkmnpqrstuvwxyzABCDEFGHKMNPQRSTUVWXYZ23456789"
  
else if button returned of recordResult is "記号あり" then
  set strText to text returned of recordResult as text
  
  # set strCharSetA to "abcdefghijklmnopqrstuvwxyz"
  ##loijを使わないパターン
  set strCharSetA to "abcdefghkmnpqrstuvwxyz"
  # set strCharSetB to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  ##Oとiを使わないパターン
  set strCharSetB to "ABCDEFGHJKLMNPQRSTUVWXYZ"
  set strCharSetC to "0123456789"
  set strCharSetD to "@#$%&!¥=+?_-"
  
else
return "キャンセルしました"
end if


###出力用テキスト初期化
set strOutPutText to ("") as text
###パスワードは8コ生成する
repeat 8 times
  ###パスワード用文字列の初期化
  set strLineTextA to ("") as text
  repeat numSetA times
    ###文字数を数えて
    set numCntCharSet to (count of character of strCharSetA) as integer
    ###文字数内のランダム番号
    set numRandomNo to (random number from 1 to numCntCharSet) as integer
    ###ランダム番号の文字列を取り出して
    set strTmp to character numRandomNo of strCharSetA
    ###繋げてパスワード用の文字列とする
    set strLineTextA to (strLineTextA & strTmp) as text
  end repeat
  
  set strLineTextB to ("") as text
  repeat numSetB times
    ###文字数を数えて
    set numCntCharSet to (count of character of strCharSetB) as integer
    ###文字数内のランダム番号
    set numRandomNo to (random number from 1 to numCntCharSet) as integer
    ###ランダム番号の文字列を取り出して
    set strTmp to character numRandomNo of strCharSetB
    ###繋げてパスワード用の文字列とする
    set strLineTextB to (strLineTextB & strTmp) as text
  end repeat
  
  set strLineTextC to ("") as text
  repeat numSetC times
    ###文字数を数えて
    set numCntCharSet to (count of character of strCharSetC) as integer
    ###文字数内のランダム番号
    set numRandomNo to (random number from 1 to numCntCharSet) as integer
    ###ランダム番号の文字列を取り出して
    set strTmp to character numRandomNo of strCharSetC
    ###繋げてパスワード用の文字列とする
    set strLineTextC to (strLineTextC & strTmp) as text
  end repeat
  
  set strLineTextD to ("") as text
  repeat numSetD times
    ###文字数を数えて
    set numCntCharSet to (count of character of strCharSetD) as integer
    ###文字数内のランダム番号
    set numRandomNo to (random number from 1 to numCntCharSet) as integer
    ###ランダム番号の文字列を取り出して
    set strTmp to character numRandomNo of strCharSetD
    ###繋げてパスワード用の文字列とする
    set strLineTextD to (strLineTextD & strTmp) as text
  end repeat
  set strLineText to (strLineTextA & strLineTextB & strLineTextC & strLineTextD) as text
  set listLineText to every character of strLineText as list
  set ocidLineTextArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidLineTextArrayM's addObjectsFromArray:(listLineText)
  
  ###指定の文字数分くりかえし
  set strLineOutPutText to "" as text
  ###文字数を数えて
  set numCntLineText to (count of character of strLineText) as integer
  repeat
    ###ランダム番号から
    set numRandomNo to (random number from 1 to numCntLineText) as integer
    ##対象の場所の文字を抜いて
    set ocidOutPutTmp to ocidLineTextArrayM's objectAtIndex:(numRandomNo - 1)
    ##その場所の文字は削除する
ocidLineTextArrayM's removeObjectAtIndex:(numRandomNo - 1)
    ##取り出した文字はテキストに
    set strLineOutPutText to (strLineOutPutText & (ocidOutPutTmp as text)) as text
    ##1文字減ったのでランダム番号も変わる
    set numCntLineText to numCntLineText - 1 as integer
    ###指定文字数で終了
    if numCntLineText = 0 then
      exit repeat
    end if
  end repeat
  ###パスワード用の文字列毎に改行を入れて
  set strLineText to (strLineOutPutText & "\n") as text
  ###出力用テキストにする
  set strOutPutText to (strOutPutText & strLineText) as text
end repeat


#####ダイアログを前面に
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 strIconPath to "/System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns"
set aliasIconPath to POSIX file strIconPath as alias
set recordResult to (display dialog "戻り値" with title "戻り値です" default answer strOutPutText buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)

if button returned of recordResult is "クリップボードにコピー" then
  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)
end if


|

GoogleDriveのパスを取得する


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

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


##########################################
###【1】ドキュメントのパスをNSString
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 ocidPlistFilePathURL to ocidLibraryDirURL's URLByAppendingPathComponent:("Preferences/com.google.drivefs.settings.plist")

##########################################
### 【2】PLISTを可変レコードとして読み込み
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL)

##########################################
### 【3】値の取得
set ocidStringValue to (ocidPlistDict's valueForKey:("PerAccountPreferences"))

##########################################
### 【4】DICTに読み込む
###NSDATAに
set ocidStringData to ocidStringValue's dataUsingEncoding:(refMe's NSUTF8StringEncoding)
###JSONSerialization
set ocidOption to refMe's NSJSONReadingMutableContainers
set listJSONSerialization to refMe's NSJSONSerialization's JSONObjectWithData:(ocidStringData) options:(ocidOption) |error|:(reference)
set ocidJsonData to item 1 of listJSONSerialization
##########################################
###ダイアログ用のリスト
set listAccount to {} as list
### 【5】複数アカウント
set ocidAccountArray to (ocidJsonData's valueForKeyPath:("per_account_preferences"))
###アカウントの数だけ繰り返し
repeat with itemAccountArray in ocidAccountArray
  ###OS12以降は
  set ocidDirPath to (itemAccountArray's valueForKeyPath:("value.mount_point_path"))
  set ocidDirName to ocidDirPath's lastPathComponent()
  set end of listAccount to (ocidDirName as text)
  ###OS12以前の場合はこちら
  # set end of listAccount to (ocidDirPath as text)
  ###リストにフォルダ名=アカウント名を取得する
  
end repeat
##########################################
### 【6】ダイアログ
try
  ###ダイアログを前面に出す
  tell current application
    set strName to name as text
  end tell
  if strName is "osascript" then
    tell application "Finder"
      activate
    end tell
  else
    tell current application
      activate
    end tell
  end if
  set listResponse to (choose from list listAccount with title "選んでください" with prompt "選んでください" default items (item 1 of listAccount) 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 strDirName to (item 1 of listResponse) as text

##########################################
### 【7】開く
###
if strDirName contains "/" then
  set strCoreStoragePath to (strDirName) as text
  set ocidGoogleDriveDirPathStr to refMe's NSString's stringWithString:(strCoreStoragePath)
  set ocidGoogleDriveDirPath to ocidGoogleDriveDirPathStr's stringByStandardizingPath()
  set ocidGoogleDriveDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidGoogleDriveDirPath) isDirectory:false)
else
  set strCoreStoragePath to ("CloudStorage/" & strDirName) as text
  ###NSURLにしておいて
  set ocidGoogleDriveDirPathURL to ocidLibraryDirURL's URLByAppendingPathComponent:(strCoreStoragePath)
end if
##パスにして
set ocidGoogleDriveDirPath to ocidGoogleDriveDirPathURL's |path|()
###パスの有無を確認
set boolDirExists to appFileManager's fileExistsAtPath:(ocidGoogleDriveDirPath) isDirectory:(true)
if boolDirExists = true then
  ###パスがあるなら開く
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
appSharedWorkspace's selectFile:(missing value) inFileViewerRootedAtPath:(ocidGoogleDriveDirPath)
else if boolDirExists = false then
return "ディレクトリが見つかりません"
end if








|

濁音 半濁音 レコード


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

###【1】半角カナ 濁音 半濁音 レコード
set recordKanaDakuon to {|ガ|:"ガ", |ギ|:"ギ", |グ|:"グ", |ゲ|:"ゲ", |ゴ|:"ゴ", |ザ|:"ザ", |ジ|:"ジ", |ズ|:"ズ", |ゼ|:"ゼ", |ゾ|:"ゾ", |ダ|:"ダ", |ヂ|:"ヂ", |ヅ|:"ヅ", |デ|:"デ", |ド|:"ド", |バ|:"バ", |ビ|:"ビ", |ブ|:"ブ", |ベ|:"ベ", |ボ|:"ボ", |パ|:"パ", |ピ|:"ピ", |プ|:"プ", |ペ|:"ペ", |ポ|:"ポ"} as record
set ocidKanaDakuonDict to refMe's NSDictionary's alloc()'s initWithDictionary:(recordKanaDakuon)
set ocidKanaDakuonKeyArray to ocidKanaDakuonDict's allKeys()

###【2】半角カナ 濁音 半濁音 別文字 レコード
set recordKanaDakuonW to {|ガ|:"ガ", |ギ|:"ギ", |グ|:"グ", |ゲ|:"ゲ", |ゴ|:"ゴ", |ザ|:"ザ", |ジ|:"ジ", |ズ|:"ズ", |ゼ|:"ゼ", |ゾ|:"ゾ", |ダ|:"ダ", |ヂ|:"ヂ", |ヅ|:"ヅ", |デ|:"デ", |ド|:"ド", |バ|:"バ", |ビ|:"ビ", |ブ|:"ブ", |ベ|:"ベ", |ボ|:"ボ", |パ|:"パ", |ピ|:"ピ", |プ|:"プ", |ペ|:"ペ", |ポ|:"ポ"} as record
set ocidKanaDakuonWDict to refMe's NSDictionary's alloc()'s initWithDictionary:(recordKanaDakuonW)
set ocidKanaDakuonWKeyArray to ocidKanaDakuonWDict's allKeys()

###【3】全角カナ 濁音 半濁音 別文字 レコード
set recordKanaWDakuonW to {|ガ|:"ガ", |ギ|:"ギ", |グ|:"グ", |ゲ|:"ゲ", |ゴ|:"ゴ", |ザ|:"ザ", |ジ|:"ジ", |ズ|:"ズ", |ゼ|:"ゼ", |ゾ|:"ゾ", |ダ|:"ダ", |ヂ|:"ヂ", |ヅ|:"ヅ", |デ|:"デ", |ド|:"ド", |バ|:"バ", |ビ|:"ビ", |ブ|:"ブ", |ベ|:"ベ", |ボ|:"ボ", |パ|:"パ", |ピ|:"ピ", |プ|:"プ", |ペ|:"ペ", |ポ|:"ポ"} as record
set ocidKanaWDakuonWDict to refMe's NSDictionary's alloc()'s initWithDictionary:(recordKanaWDakuonW)
set ocidKanaWDakuonWKeyArray to ocidKanaWDakuonWDict's allKeys()

###【4】全角ひら 濁音 半濁音 別文字 レコード
set recordHiraKanaDakuonW to {|が|:"が", |ぎ|:"ぎ", |ぐ|:"ぐ", |げ|:"げ", |ご|:"ご", |ざ|:"ざ", |じ|:"じ", |ず|:"ず", |ぜ|:"ぜ", |ぞ|:"ぞ", |だ|:"だ", |ぢ|:"ぢ", |づ|:"づ", |で|:"で", |ど|:"ど", |ば|:"ば", |び|:"び", |ぶ|:"ぶ", |べ|:"べ", |ぼ|:"ぼ", |ぱ|:"ぱ", |ぴ|:"ぴ", |ぷ|:"ぷ", |ぺ|:"ぺ", |ぽ|:"ぽ"} as record
set recordHiraKanaDakuonWDict to refMe's NSDictionary's alloc()'s initWithDictionary:(recordHiraKanaDakuonW)
set ocidHiraKanaDakuonWKeyArray to recordHiraKanaDakuonWDict's allKeys()

###【5】半角レコード
set recordKana to {|。|:"。", |「|:"「", |」|:"」", |、|:"、", |・|:"・", |ヲ|:"ヲ", |ァ|:"ァ", |ィ|:"ィ", |ゥ|:"ゥ", |ェ|:"ェ", |ォ|:"ォ", |ャ|:"ャ", |ュ|:"ュ", |ョ|:"ョ", |ッ|:"ッ", |ー|:"ー", |ア|:"ア", |イ|:"イ", |ウ|:"ウ", |エ|:"エ", |オ|:"オ", |カ|:"カ", |キ|:"キ", |ク|:"ク", |ケ|:"ケ", |コ|:"コ", |サ|:"サ", |シ|:"シ", |ス|:"ス", |セ|:"セ", |ソ|:"ソ", |タ|:"タ", |チ|:"チ", |ツ|:"ツ", |テ|:"テ", |ト|:"ト", |ナ|:"ナ", |ニ|:"ニ", |ヌ|:"ヌ", |ネ|:"ネ", |ノ|:"ノ", |ハ|:"ハ", |ヒ|:"ヒ", |フ|:"フ", |ヘ|:"ヘ", |ホ|:"ホ", |マ|:"マ", |ミ|:"ミ", |ム|:"ム", |メ|:"メ", |モ|:"モ", |ヤ|:"ヤ", |ユ|:"ユ", |ヨ|:"ヨ", |ラ|:"ラ", |リ|:"リ", |ル|:"ル", |レ|:"レ", |ロ|:"ロ", |ワ|:"ワ", |ン|:"ン"} as record
set ocidKanaDict to refMe's NSDictionary's alloc()'s initWithDictionary:(recordKana)
set ocidKanaKeyArray to ocidKanaDict's allKeys()

|

[UnInstall]パセリrcs300ドライバーアン・インストール

#!/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.4"
use framework "Foundation"

use scripting additions

property refMe : a reference to current application
set objFileManager to refMe's NSFileManager's defaultManager()


###NSOperatingSystemVersion
set recordOsVersion to (refMe's NSProcessInfo's processInfo)'s operatingSystemVersion()
set numMajorVersion to recordOsVersion's majorVersion() as integer
-->13
####対象のパス
set strFilePath to "/usr/local/libexec/SmartCardServices/drivers/ifd-ccid-rcs300.bundle" as text
####OSが13以上なら
if numMajorVersion ≥ 13 then
    ####パス
    set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
    set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
    ####有無チェック
    set boolFileExist to (ocidFilePathURL's checkResourceIsReachableAndReturnError:(missing value))
    if boolFileExist is false then
        log "OS13以上で旧ドライバーがありません未インストール=このケースは無いのが正"
        return "ファイルがありません未インストール=このケースはこれでOK処理終了"
    else
        log "OS13以上で旧ドライバーがあります-->削除処理を実行します"
    end if
    log boolFileExist
    return
    set listResult to (objFileManager's trashItemAtURL:ocidFilePathURL resultingItemURL:(missing value) |error|:(reference))
    
    if (item 1 of listResult) is false then
        set ocidUserTrashPathArray to (objFileManager's URLsForDirectory:(refMe's NSTrashDirectory) inDomains:(refMe's NSUserDomainMask))
        set ocidUserTrashPathURL to ocidUserTrashPathArray's objectAtIndex:0
        set ocidUserTrashPath to ocidUserTrashPathURL's |path|()
        set strUserTrashPath to ocidUserTrashPath as text
        set theComandText to ("/bin/mv \"" & strFilePath & "\" \"" & strUserTrashPath & "\"") as text
        do shell script theComandText with administrator privileges
        log "ゴミ箱に入れましたデバイスの電源OFF->ON再起動してください"
    else
        log "ゴミ箱に入れましたデバイスの電源OFF->ON再起動してください"
        return
    end if
    ####OS13以下の場合は必要なので処理しない
else
    log "macOS13 以下には必須です"
    return
end if

|

[Admin]Osのバージョンを求める


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

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



################################
####OSのバージョン
set ocidProcessInfo to refMe's NSProcessInfo's processInfo()
set ocidOsVersion to ocidProcessInfo's operatingSystemVersion()

set numMajorVersion to (item 1 of ocidOsVersion) as integer
set numMinorVersion to (item 2 of ocidOsVersion) as integer
set numPatchVersion to (item 3 of ocidOsVersion) as integer

log numMajorVersion
log numMinorVersion
log numPatchVersion

log ocidProcessInfo's operatingSystemVersionString as text



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

set recordSystemInfo to system info
set strVersion to (system version of recordSystemInfo) as text
log strVersion

tell application "Finder"
  set strVersion to version as text
  log strVersion
end tell


#!/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.4"
use framework "Foundation"

use scripting additions

property refMe : a reference to current application


###NSOperatingSystemVersion
set recordOsVersion to (refMe's NSProcessInfo's processInfo)'s operatingSystemVersion()
-->(*majorVersion:13, minorVersion:2, patchVersion:0*)

set strMajorVersion to recordOsVersion's majorVersion()
-->13

set strOsVersion to (refMe's NSProcessInfo's processInfo)'s operatingSystemVersionString()
-->(*バージョン13.2(ビルド22D49*)

tell application "Finder"
    set strVersion to version as text
end tell
-->13.2

set strSystemVersion to do shell script "sw_vers -productVersion| cut -b-5" as text
--> "13.2"

set strFilePath to "/System/Library/CoreServices/SystemVersion.plist" as text
set strSystemVersion to do shell script "/usr/bin/defaults read " & strFilePath & " ProductVersion" as text
--> "13.2"

|

[JAVA]JAVA関連のファイルをゴミ箱に入れる

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

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


set strFilePath to "~/.Trash"
set ocidRelativePath to refNSString's stringWithString:strFilePath
-->(*~/.Trash*)(*__NSCFString*)
set ocidFullPath to ocidRelativePath's stringByStandardizingPath
-->(*/Users/ユーザー名/.Trash*)(*NSPathStore2*)
set ocidTrashURL to refNSURL's alloc()'s initFileURLWithPath:ocidFullPath
set strTrashPath to ocidTrashURL's fileSystemRepresentation() as text


set strCommandText to "/usr/bin/sudo /bin/mv /Library/LaunchAgents/com.oracle.java* \"" & strTrashPath & "\""
log strCommandText as text
try
do shell script strCommandText with administrator privileges
end try

set strCommandText to "/usr/bin/sudo /bin/mv /Library/LaunchDaemons/com.oracle.java* \"" & strTrashPath & "\""
log strCommandText as text
try
do shell script strCommandText with administrator privileges
end try

set strCommandText to "/usr/bin/sudo /bin/mv \"/Library/Internet Plug-Ins/JavaAppletPlugin.plugin\" \"" & strTrashPath & "\""
log strCommandText as text
try
do shell script strCommandText with administrator privileges
end try



set strCommandText to "/usr/bin/sudo /bin/mv \"/Library/PreferencesPanes/JavaControlPanel.prefPane\" \"" & strTrashPath & "\""
log strCommandText as text
try
do shell script strCommandText with administrator privileges
end try


set strCommandText to "/usr/bin/sudo /bin/mv \"/Library/Java/JavaVirtualMachines\" \"" & strTrashPath & "\""
log strCommandText as text
try
do shell script strCommandText with administrator privileges
end try

set strCommandText to "/usr/bin/sudo /bin/mv \"/Library/Application Support/Oracle/Java\" \"" & strTrashPath & "\""
log strCommandText as text
try
do shell script strCommandText with administrator privileges
end try


set strCommandText to "/usr/bin/sudo /bin/mv $HOME/Library/Application\\ Support/Oracle/Java \"" & strTrashPath & "\""
log strCommandText as text
try
do shell script strCommandText with administrator privileges
end try

set strCommandText to "/usr/bin/sudo /bin/mv $HOME/Library/Internet\\ Plug-Ins/JavaAppletPlugin.plugin \"" & strTrashPath & "\""
log strCommandText as text
try
do shell script strCommandText with administrator privileges
end try

set strCommandText to "/usr/bin/sudo /bin/mv $HOME/Library/Preferences/com.oracle.java* \"" & strTrashPath & "\""
log strCommandText as text
try
do shell script strCommandText with administrator privileges
end try


set strCommandText to "/usr/bin/sudo /bin/mv $HOME/Library/LaunchAgents/com.oracle.java* \"" & strTrashPath & "\""
log strCommandText as text
try
do shell script strCommandText with administrator privileges
end try

|

[open location]ゲスト (AUTH=No User Authent)

afp://[user[;AUTH=uamname][:password]@]host[:port]/volumename
mount_afp "afp://;AUTH=No%20User%20Authent@myserver/guestVolume" /Volumes/guest


tell application "Finder"


set strUrl to "ftp://;AUTH=No%20User%20Authent@192.168.0.0" as text

open location strUrl


end tell




afp://ユーザー名:パスワード@192.168.0.0/Public


ftp://;AUTH=No%20User%20Authent@foo.hoge.com/Public

ftp://anonymous:guest@192.168.0.0/Public

ftp://guest:guest@192.168.0.0/Public


smb://;AUTH=No%20User%20Authent@foo.hoge.com/Public

smb://anonymous:guest@192.168.0.0/Public

smb://guest:guest@192.168.0.0/Public


afp://;AUTH=No%20User%20Authent@foo.hoge.com/Public

afp://anonymous:guest@192.168.0.0/Public

afp://guest:guest@192.168.0.0/Public


|

[iCloud]スクリプトメニューにクラウドのLINKを作る

これやるとメニューの応答に時間がかかるようになったので
すぐやめたやつ…


do shell script "mkdir -pm 777 $HOME/Library/Scripts/Finder/CloudDrive/iCloudLink"

(*
do shell script "ln -s $HOME/Library/CloudStorage/OneDrive-個人用 $HOME/Library/Scripts/Finder/CloudDrive/OneDrive"
do shell script "ln -s $HOME/Library/CloudStorage/Box-Box $HOME/Library/Scripts/Finder/CloudDrive/Box"
do shell script "ln -s $HOME/Creative\\ Cloud\\ Files $HOME/Library/Scripts/Finder/CloudDrive/Creative\\ Cloud\\ Files"
do shell script "ln -s $HOME/Dropbox $HOME/Library/Scripts/Finder/CloudDrive/Dropbox"

*)


set lisrDirList to {"F3LWYJ7GM7~com~apple~garageband10", "F3LWYJ7GM7~com~apple~mobilegarageband", "F3LWYJ7GM7~com~apple~musicmemos~ideas", "F6266T9T75~com~apple~iMovie", "com~apple~Automator", "com~apple~CloudDocs", "com~apple~Keynote", "com~apple~Numbers", "com~apple~Pages", "com~apple~Preview", "com~apple~QuickTimePlayerX", "com~apple~SafariShared~History", "com~apple~ScriptEditor2", "com~apple~TextEdit", "com~apple~TextInput", "com~apple~iBooks~cloudData", "com~apple~mail", "com~apple~mobilemail", "com~apple~notes", "com~apple~shoebox", "iCloud~com~adobe~Adobe-Reader", "iCloud~com~adobe~sketchdraw~fileaccess", "iCloud~com~amazon~Drive", "iCloud~com~apple~DocumentsApp", "iCloud~com~apple~MobileSMS", "iCloud~com~apple~Playgrounds", "iCloud~com~apple~clips", "iCloud~com~apple~configurator~ui", "iCloud~com~apple~iBooks", "iCloud~com~apple~iBooks~iTunesU", "iCloud~com~apple~itunesu", "iCloud~com~apple~mobilesafari", "iCloud~com~apple~passd", "iCloud~com~apple~shortcuts~runtime", "iCloud~com~barebones~bbedit", "iCloud~com~coteditor~CotEditor", "iCloud~com~evernote~iPhone~Evernote", "iCloud~com~fujifilm~fb~multicopy~container", "iCloud~com~fujifilm~fb~netprint~kantan", "iCloud~com~microsoft~Office~Excel", "iCloud~com~microsoft~Office~PowerPoint", "iCloud~com~microsoft~Office~Word", "iCloud~com~microsoft~lync2013~iphone", "iCloud~com~microsoft~officemobile", "iCloud~com~microsoft~onenote", "iCloud~com~microsoft~skydrive", "iCloud~com~microsoft~skype~teams", "iCloud~com~microsoft~visio", "iCloud~com~nttdocomo~CloudStorageService", "iCloud~com~omnigroup~OmniFocus", "iCloud~com~omnigroup~OmniGraffle", "iCloud~com~omnigroup~OmniOutliner", "iCloud~com~omnigroup~OmniPlan", "iCloud~jp~co~artman21~JeditOmega", "iCloud~us~zoom~videomeetings"} as list


repeat with objDirList in lisrDirList
set strDirList to objDirList as text
try
set strCommandText to "ln -s $HOME/Library/Mobile\\ Documents/" & strDirList & " $HOME/Library/Scripts/Finder/CloudDrive/iCloudLink/" & strDirList & ""
do shell script strCommandText
end try
end repeat

|

[TEXT]テキストデータに行番号を入れる(3桁ゼロサプレス)

#!/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 objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSMutableString : a reference to objMe's NSMutableString
property objNSURL : a reference to objMe's NSURL
property objNSMutableArray : a reference to objMe's NSMutableArray

property objNSNotFound : a reference to 9.22337203685477E+18 + 5807

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

######ログ表示
doLogView()
####ダイアログで使うデフォルトロケーション
set ocidUserDesktopPath to (objFileManager's URLsForDirectory:(objMe's NSDesktopDirectory) inDomains:(objMe's NSUserDomainMask)) as alias

####UTIリスト PDFのみ
set listUTI to {"public.plain-text"} as list

####ダイアログを出す
set aliasFilePath to (choose file with prompt "ファイルを選んでください" default location (ocidUserDesktopPath) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias

set strFilePath to POSIX path of aliasFilePath as text
####ドキュメントのパスをNSString
set ocidFilePath to objNSString's stringWithString:strFilePath
####ドキュメントのパスをNSURL
set ocidNSUrlPath to objNSURL's fileURLWithPath:ocidFilePath
####ファイル名
set ocidFileName to ocidNSUrlPath's lastPathComponent
####拡張子を除いたファイル名
set ocidPrefixName to ocidFileName's stringByDeletingPathExtension

####ファイルを読み取る
set strReadData to (objNSString's stringWithContentsOfFile:ocidFilePath encoding:(current application's NSUTF8StringEncoding) |error|:(missing value)) as text
#####テキストの内容
log strReadData
################################################
###可変テキスト初期化
set ocidReadData to objNSMutableString's alloc()'s initWithCapacity:0
###テキストデータを流し込み
ocidReadData's setString:strReadData
###↑文字数を数える
set numCntSampleText to ocidReadData's |length|()
###↑文字数全部でレンジにする
set ocidNsRange to {location:0, |length|:numCntSampleText}
###改行コード置き換え(CR/LF)
ocidReadData's replaceOccurrencesOfString:"\r\n" withString:"\n" options:0 range:ocidNsRange
###↑文字数を数える
set numCntSampleText to ocidReadData's |length|()
###↑文字数全部でレンジにする
set ocidNsRange to {location:0, |length|:numCntSampleText}
###改行コード置き換え(CR)
ocidReadData's replaceOccurrencesOfString:"\r" withString:"\n" options:0 range:ocidNsRange
###改行でリストにする
set ocidReadDataNSArray to ocidReadData's componentsSeparatedByString:"\n"
#####################
set numLineNo to 0 as number
set strOutData to "" as text
#####
repeat with objReadDataNSArray in ocidReadDataNSArray
set strReadDataNSArray to objReadDataNSArray as text
set numLineNo to numLineNo + 1 as number
if numLineNo < 100 then
set strZeroAdd to ("000" & numLineNo) as text
set strLineNo to text -3 through -1 of strZeroAdd as text
end if
set strOutData to strOutData & strLineNo & "\t" as text
set strOutData to strOutData & strReadDataNSArray & "\n" as text
end repeat

################################################
###処理が終わったテキスト
set ocidTempText to objNSString's stringWithString:strOutData
######################
###フォルダのパス
###デスクトップフォルダのパス
set aliasDirPath to (path to desktop folder from user domain) as alias
set strDirPath to POSIX path of aliasDirPath as text
####作りたいファイル名(ここは今日の日付)
set strDateAndTimeJp to (my dateFormatterWithFormat:"yyyyMMdd-HHmm")
set strDistFilePath to ("" & strDirPath & ocidPrefixName & "-" & strDateAndTimeJp & ".txt")

###NSStringテキスト ファイルのパス
set objDistFilePath to objNSString's stringWithString:strDistFilePath

###ファイルを作る
set boolMakeNewFile to (objFileManager's createFileAtPath:objDistFilePath |contents|:ocidTempText attributes:(missing value))
####内容を書き込む UTF8で書き込む
set boolFileWrite to (ocidTempText's writeToFile:objDistFilePath atomically:false encoding:(objMe's NSUTF8StringEncoding) |error|:(missing value))

log boolMakeNewFile
log boolFileWrite
-->true or false





###日付のサブ
on dateFormatterWithFormat:classDateFormat
set formatter to objMe's NSDateFormatter's alloc()'s init()
formatter's setLocale:(objMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
formatter's setDateFormat:(classDateFormat as string)
set theString to (formatter's stringFromDate:(current date)) as text
end dateFormatterWithFormat:







#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat

end doLogView
#########################

|

その他のカテゴリー

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