AppleScript Finder

ファイル名のフォルダを作ってファイルを中に移動する(リネーム対応)


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

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

on run
  ##デスクトップ
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
  set aliasDesktopDirPath to ocidDesktopDirPathURL's absoluteURL() as alias
  ###ダイアログを前面に出す
  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 strMes to ("ファイルを選んでください") as text
  set strPrompt to ("ファイルを選んでください") as text
  set listUTI to {"public.item"} as list
  set listAliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDesktopDirPath) of type listUTI with multiple selections allowed and showing package contents without invisibles) as list
open listAliasFilePath
end run


on open listAliasFilePath
  -->ドロップレットアプリケーションに書き出すとフォルダでも出来ます
  ##繰り返しのはじまり
  repeat with itemAliasFilePath in listAliasFilePath
    set aliasFilePath to itemAliasFilePath as alias
    set strFilePath to (POSIX path of aliasFilePath) as text
    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
    ##拡張子
    set ocidExtensionName to ocidFilePathURL's pathExtension()
    ##拡張子をとって
    set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
    #↑これがフォルダのパス
    set ocidMakeDirPathURL to ocidBaseFilePathURL
    ##ファイル名(拡張子無し)
    set ocidBaseFileName to ocidBaseFilePathURL's lastPathComponent()
    ##ファイル名(拡張子あり)
    set ocidFileName to ocidFilePathURL's lastPathComponent()
    ##フォルダを作るディレクトリ
    set ocidConteinerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
    ##フォルダパス+ファイル名で移動先
    set ocidMoveFilePathURL to (ocidMakeDirPathURL's URLByAppendingPathComponent:(ocidFileName))
    ##作ろうとしているディレクトリがすでに無いか?確認
    set ocidMakeDirPath to ocidMakeDirPathURL's |path|()
    set appFileManager to refMe's NSFileManager's defaultManager()
    set boolDirExists to (appFileManager's fileExistsAtPath:(ocidMakeDirPath) isDirectory:(true))
    if boolDirExists = true then
log "フォルダがすでにある"
    else if boolDirExists = false then
log "フォルダを作る"
      set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
      # 777-->511 755-->493 700-->448 766-->502
(ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions))
      set listBoolMakeDir to (appFileManager's createDirectoryAtURL:(ocidMakeDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
    end if
    ##重複チェック
    set ocidDistFilePath to doChkExists(ocidMoveFilePathURL)
    set ocidDistFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidDistFilePath) isDirectory:false)
    if ocidMoveFilePathURL = ocidMoveFilePathURL then
log "置換します"
      #今あるファイルをゴミ箱に
      set listResult to (appFileManager's trashItemAtURL:(ocidDistFilePathURL) resultingItemURL:(ocidDistFilePathURL) |error|:(reference))
      #移動
      set ListDone to (appFileManager's moveItemAtURL:(ocidFilePathURL) toURL:(ocidDistFilePathURL) |error|:(reference))
    else
      #移動
      set ListDone to (appFileManager's moveItemAtURL:(ocidFilePathURL) toURL:(ocidDistFilePathURL) |error|:(reference))
    end if
    set boolDone to (item 1 of ListDone) as boolean
    if boolDone is false then
return "移動に失敗しました"
    end if
  end repeat
end open




####################################
#上書きチェック
# ocid file path = NSPathStore を返します
####################################
to doChkExists(argFilePath)
log (className() of argFilePath) as text
  if (class of argFilePath) is text then
log "テキストファイルパス"
    set ocidFilePathStr to refMe's NSString's stringWithString:(argFilePath)
    set ocidArgFilePath to ocidFilePathStr's stringByStandardizingPath()
  else if (class of argFilePath) is alias then
log "エリアスファイルパス"
    set strArgFilePath to (POSIX path of argFilePath) as text
    set ocidFilePathStr to refMe's NSString's stringWithString:(argFilePath)
    set ocidArgFilePath to ocidFilePathStr's stringByStandardizingPath()
  else if (class of argFilePath) is «class furl» then
log "エリアスfurlファイルパス"
    set aliasFilePath to argFilePath as alias
    set strArgFilePath to (POSIX path of argFilePath) as text
    set ocidFilePathStr to refMe's NSString's stringWithString:(argFilePath)
    set ocidArgFilePath to ocidFilePathStr's stringByStandardizingPath()
  else if (className() of argFilePath as text) contains "NSCFString" then
log "NSStringファイルパス"
    set ocidArgFilePath to argFilePath's stringByStandardizingPath()
  else if (className() of argFilePath as text) contains "NSPathStore" then
log "NSPathStore2ファイルパス"
    set ocidArgFilePath to argFilePath
  else if (className() of argFilePath as text) contains "NSURL" then
log "NSURLファイルパス"
    set ocidArgFilePath to argFilePath's |path|
  end if
  ####
  set appFileManager to refMe's NSFileManager's defaultManager()
  set boolExists to appFileManager's fileExistsAtPath:(ocidArgFilePath) isDirectory:(false)
  #
  if boolExists = true then
    ##ダイアログを前面に
    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 strMes to "上書きします?" as text
    try
      set objResponse to (display alert strMes buttons {"上書きする", "処理を中止する", "ファイル名を変更"} default button "上書きする" cancel button "処理を中止する" as informational giving up after 20)
    on error
log "処理を中止しました"
return "処理を中止しました"
      error number -128
    end try
    if true is equal to (gave up of objResponse) then
log "時間切れですやりなおしてください"
return "時間切れですやりなおしてください"
      error number -128
    end if
    if "上書きする" is equal to (button returned of objResponse) then
log "上書き保存します"
      set ocidReturnFilePath to ocidArgFilePath
    else if "ファイル名を変更" is equal to (button returned of objResponse) then
log "ファイル名を変更"
      set ocidContainerDirFilePath to ocidArgFilePath's stringByDeletingLastPathComponent()
      set strFileName to ocidArgFilePath's lastPathComponent() as text
      set aliasContainerDirPath to (POSIX file (ocidContainerDirFilePath as text)) as alias
      ##
      set strPromptText to "名前を決めてください" as text
      set strMesText to "名前を決めてください" as text
      ###ファイル名 ダイアログ
      set aliasFilePath to (choose file name strMesText default location aliasContainerDirPath default name strFileName with prompt strPromptText) as «class furl»
      set strFilePath to (POSIX path of aliasFilePath) as text
      set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
      set ocidReturnFilePath to ocidFilePathStr's stringByStandardizingPath()
    else if "処理を中止する" is equal to (button returned of objResponse) then
return "処理を中止しました"
    else
return "エラーしました"
      error number -128
    end if
  else if boolExists = false then
log "そのままファイル生成"
    set ocidReturnFilePath to ocidArgFilePath
  end if
return ocidReturnFilePath
  
end doChkExists

|

ファイル名のフォルダを作ってファイルを中に移動する


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

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

on run
  ##デスクトップ
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
  set aliasDesktopDirPath to ocidDesktopDirPathURL's absoluteURL() as alias
  ###ダイアログを前面に出す
  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 strMes to ("ファイルを選んでください") as text
  set strPrompt to ("ファイルを選んでください") as text
  set listUTI to {"public.item"} as list
  set listAliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDesktopDirPath) of type listUTI with multiple selections allowed and showing package contents without invisibles) as list
open listAliasFilePath
end run


on open listAliasFilePath
  -->ドロップレットアプリケーションに書き出すとフォルダでも出来ます
  ##繰り返しのはじまり
  repeat with itemAliasFilePath in listAliasFilePath
    set aliasFilePath to itemAliasFilePath as alias
    set strFilePath to (POSIX path of aliasFilePath) as text
    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
    ##拡張子
    set ocidExtensionName to ocidFilePathURL's pathExtension()
    ##拡張子をとって
    set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
    #↑これがフォルダのパス
    set ocidMakeDirPathURL to ocidBaseFilePathURL
    ##ファイル名(拡張子無し)
    set ocidBaseFileName to ocidBaseFilePathURL's lastPathComponent()
    ##ファイル名(拡張子あり)
    set ocidFileName to ocidFilePathURL's lastPathComponent()
    ##フォルダを作るディレクトリ
    set ocidConteinerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
    ##フォルダパス+ファイル名で移動先
    set ocidMoveFilePathURL to (ocidMakeDirPathURL's URLByAppendingPathComponent:(ocidFileName))
    ##作ろうとしているディレクトリがすでに無いか?確認
    set ocidMakeDirPath to ocidMakeDirPathURL's |path|()
    set appFileManager to refMe's NSFileManager's defaultManager()
    set boolDirExists to (appFileManager's fileExistsAtPath:(ocidMakeDirPath) isDirectory:(true))
    if boolDirExists = true then
log "フォルダがすでにある"
    else if boolDirExists = false then
log "フォルダを作る"
      set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
      # 777-->511 755-->493 700-->448 766-->502
(ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions))
      set listBoolMakeDir to (appFileManager's createDirectoryAtURL:(ocidMakeDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
    end if
    ##移動
    set ListDone to (appFileManager's moveItemAtURL:(ocidFilePathURL) toURL:(ocidMoveFilePathURL) |error|:(reference))
    set boolDone to (item 1 of ListDone) as boolean
    if boolDone is false then
log "移動に失敗しました"
      set numCntReplace to 1 as integer
      repeat
        set strBaseFileName to ocidBaseFileName as text
        ##ファイルのリネームはここですのでお好みで変更ください
        set strReplaceFileName to (strBaseFileName & "@" & numCntReplace) as text
        set ocidReplaceBaseFilePathURL to (ocidMakeDirPathURL's URLByAppendingPathComponent:(strReplaceFileName))
        set ocidReplaceFilePathURL to (ocidReplaceBaseFilePathURL's URLByAppendingPathExtension:(ocidExtensionName))
        set ListDone to (appFileManager's moveItemAtURL:(ocidFilePathURL) toURL:(ocidReplaceFilePathURL) |error|:(reference))
        set boolDone to (item 1 of ListDone) as boolean
        if boolDone is true then
log strReplaceFileName & "にリネームしました"
          exit repeat
        else
          set numCntReplace to (numCntReplace + 1) as integer
        end if
      end repeat
      ##
    end if
    
  end repeat
end open


|

Finder再起動(QuickLookも)


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

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

set strBundleID to "com.apple.finder"


##バンドルからアプリケーションのURLを取得
set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(strBundleID))
if ocidAppBundle ≠ (missing value) then
  set ocidAppPathURL to ocidAppBundle's bundleURL()
else if ocidAppBundle = (missing value) then
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID))
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

##終了
set ocidRunningApplication to refMe's NSRunningApplication
###起動中のすべてのリスト
set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID))
###複数起動時も順番に終了
repeat with itemAppArray in ocidAppArray
  ###終了
itemAppArray's terminate()
end repeat
##1秒まって終了を確認
delay 1
##終了できない場合は強制終了
repeat with itemAppArray in ocidAppArray
  set boolTerminate to itemAppArray's terminated
  if boolTerminate = false then
itemAppArray's forceTerminate()
  end if
end repeat
###起動
set ocidOpenConfig to refMe's NSWorkspaceOpenConfiguration's configuration
###コンフィグ
(ocidOpenConfig's setActivates:(refMe's NSNumber's numberWithBool:true))
###起動
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
(appSharedWorkspace's openApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value))


###ついでにQuickLOOK関連も再起動しておく

set strBundleID to "br.com.guilhermerambo.AssetCatalog"
##終了
set ocidRunningApplication to refMe's NSRunningApplication
###起動中のすべてのリスト
set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID))
###複数起動時も順番に終了
repeat with itemAppArray in ocidAppArray
  ###終了
itemAppArray's terminate()
end repeat
##1秒まって終了を確認
delay 1
##終了できない場合は強制終了
repeat with itemAppArray in ocidAppArray
  set boolTerminate to itemAppArray's terminated
  if boolTerminate = false then
itemAppArray's forceTerminate()
  end if
end repeat

set strBundleID to "com.latenightsw.sdquicklookgenerator"
##終了
set ocidRunningApplication to refMe's NSRunningApplication
###起動中のすべてのリスト
set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID))
###複数起動時も順番に終了
repeat with itemAppArray in ocidAppArray
  ###終了
itemAppArray's terminate()
end repeat
##1秒まって終了を確認
delay 1
##終了できない場合は強制終了
repeat with itemAppArray in ocidAppArray
  set boolTerminate to itemAppArray's terminated
  if boolTerminate = false then
itemAppArray's forceTerminate()
  end if
end repeat

set strBundleID to "com.apple.quicklook.QuickLookUIService"
##終了
set ocidRunningApplication to refMe's NSRunningApplication
###起動中のすべてのリスト
set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID))
###複数起動時も順番に終了
repeat with itemAppArray in ocidAppArray
  ###終了
itemAppArray's terminate()
end repeat
##1秒まって終了を確認
delay 1
##終了できない場合は強制終了
repeat with itemAppArray in ocidAppArray
  set boolTerminate to itemAppArray's terminated
  if boolTerminate = false then
itemAppArray's forceTerminate()
  end if
end repeat

|

[AppleScript]ファイル名のフォルダを作ってファイルをその中に入れる

ダウンロード - makefolder2filename.zip


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

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

property refMe : a reference to current application

on run
  ##デスクトップ
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
  set aliasDesktopDirPath to ocidDesktopDirPathURL's absoluteURL() as alias
  ###ダイアログを前面に出す
  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 strMes to ("ファイルを選んでください") as text
  set strPrompt to ("ファイルを選んでください") as text
  set listUTI to {"public.item"} as list
  set listAliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDesktopDirPath) of type listUTI with multiple selections allowed and showing package contents without invisibles) as list
open listAliasFilePath
end run


on open listAliasFilePath
  -->ドロップレットアプリケーションに書き出すとフォルダでも出来ます
  ##繰り返しのはじまり
  repeat with itemAliasFilePath in listAliasFilePath
    set aliasFilePath to itemAliasFilePath as alias
    set strFilePath to (POSIX path of aliasFilePath) as text
    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
    ##拡張子をとって
    set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
    #↑これがフォルダのパス
    set ocidMakeDirPathURL to ocidBaseFilePathURL
    ##ファイル名(拡張子無し)
    set ocidBaseFileName to ocidBaseFilePathURL's lastPathComponent()
    ##ファイル名(拡張子あり)
    set ocidFileName to ocidFilePathURL's lastPathComponent()
    ##フォルダを作るディレクトリ
    set ocidConteinerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
    ##フォルダパス+ファイル名で移動先
    set ocidMoveFilePathURL to (ocidMakeDirPathURL's URLByAppendingPathComponent:(ocidFileName))
    ##作ろうとしているディレクトリがすでに無いか?確認
    set ocidMakeDirPath to ocidMakeDirPathURL's |path|()
    set appFileManager to refMe's NSFileManager's defaultManager()
    set boolDirExists to (appFileManager's fileExistsAtPath:(ocidMakeDirPath) isDirectory:(true))
    if boolDirExists = true then
log "フォルダがすでにある"
    else if boolDirExists = false then
log "フォルダを作る"
      set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
      # 777-->511 755-->493 700-->448 766-->502
(ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions))
      set listBoolMakeDir to (appFileManager's createDirectoryAtURL:(ocidMakeDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
    end if
    ##移動
    set ListDone to (appFileManager's moveItemAtURL:(ocidFilePathURL) toURL:(ocidMoveFilePathURL) |error|:(reference))
    if (item 1 of ListDone) is false then
log "移動に失敗しました"
    end if
    
  end repeat
end open

|

FinderのKind 種類のリスト

InfoPlist.loctable
jakozh_CNzh_HKzh_TW
Burn Folderディスク作成フォルダ굽기 폴더刻录文件夹燒錄資料夾燒錄檔案夾
smart folderスマートフォルダ스마트 폴더智能文件夹智慧型資料夾智慧型檔案夾
iOS Package ArchiveiOSパッケージのアーカイブiOS 패키지 아카이브iOS软件包归档iOS套裝封存檔iOS套件封存檔
Saved Search Query保存された検索クエリー저장된 검색 쿼리已存储的搜索查询已儲存的搜尋查詢已儲存的搜尋查詢
Predefined Search定義済みの検索프리셋된 검색预先定义的搜索預先定義的搜尋預先定義的搜尋
FTP Internet LocationFTPインターネットロケーションFTP 인터넷 위치FTP互联网位置FTP互聯網位置FTP網際網路位置
AFP URLAFP URLAFP URLAFP URLAFP URLAFP URL
Internet Locationインターネットロケーション인터넷 위치互联网位置互聯網位置網際網路位置
File URLファイルURL파일 URL文件URL檔案URL檔案URL
File Internet Locationファイルインターネットロケーション파일 인터넷 위치文件互联网位置檔案互聯網位置檔案網際網路位置
Mail Internet LocationメールインターネットロケーションMail 인터넷 위치邮件互联网位置郵件互聯網位置郵件網際網路位置
Text Clippingテキストクリッピング텍스트 클리핑文本剪辑文字片段文字片段
Web Internet LocationWebインターネットロケーション웹 인터넷 위치网页互联网位置網頁互聯網位置網頁網際網路位置
FTP URLFTP URLFTP URLFTP URLFTP URLFTP URL
AppleTalk Internet LocationAppleTalkインターネットロケーションAppleTalk 인터넷 위치AppleTalk互联网位置AppleTalk互聯網位置AppleTalk網際網路位置
AFP Internet LocationAFPインターネットロケーションAFP 인터넷 위치AFP互联网位置AFP互聯網位置AFP網際網路位置
Apple Device Software Update FileAppleデバイスのソフトウェアアップデートファイルApple 기기 소프트웨어 업데이트 파일Apple设备软件更新文件Apple裝置軟件更新檔案Apple裝置軟體更新檔案
CFBundleDisplayNameFinderFinder访达FinderFinder
Folderフォルダ폴더文件夹資料夾檔案夾
NSL Internet LocationNSLインターネットロケーションNSL 인터넷 위치NSL互联网位置NSL互聯網位置NSL網際網路位置
Picture Clippingピクチャクリッピング그림 클리핑图片剪辑圖片片段圖片片段
News Internet Locationニュースインターネットロケーション뉴스 인터넷 위치新闻互联网位置新聞互聯網位置新聞網際網路位置
Sound Clippingサウンドクリッピング사운드 클리핑声音剪辑聲音片段聲音片段
Clippingクリッピング클리핑剪辑片段片段
Volumeボリューム볼륨宗卷卷宗卷宗

|

[Finder]フォルダを1つ選択


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

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


###選択項目は1つ限定
tell application "Finder"
  set listPath to selection as list
end tell
set numCntSelection to (count of listPath) as integer
if numCntSelection > 1 then
display alert "複数選択されている"
  set aliasPath to doChooseFolder()
else if numCntSelection = 0 then
display alert "選択されていない"
  set aliasPath to doChooseFolder()
else if numCntSelection = 1 then
  set aliasPath to (item 1 of listPath) as alias
end if


###フォルダ限定
tell application "Finder"
  set strKind to (kind of item aliasPath) as text
end tell
if strKind is "フォルダ" then
log "フォルダです処理を継続します"
else
display alert "フォルダではありません"
  set aliasPath to doChooseFolder()
end if


set strDirPath to (POSIX path of aliasPath) as text


###ダイアログ
to doChooseFolder()
  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
  ##
  tell application "Finder"
    set aliasDefaultLocation to (path to desktop folder from user domain) as alias
  end tell
  ############
  set strMes to "フォルダを選んでください" as text
  set strPrompt to "フォルダを選択してください" as text
  set aliasResponse to (choose folder strMes with prompt strPrompt default location aliasDefaultLocation with invisibles and showing package contents without multiple selections allowed) as alias
return aliasResponse
end doChooseFolder

|

[com.apple.finder] SlicesRootAttributes その2

 

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

#!/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 appFileManager to refMe's NSFileManager's defaultManager()


##########################################
###【1】ドキュメントのパスをNSString
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
##テスト用
##set ocidPlistFilePathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/com.apple.finder.test.plist")
set ocidPlistFilePathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/com.apple.finder.plist")
##########################################
### 【2】PLISTを可変レコードとして読み込み
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL)

##########################################
### 【3】処理はここで
set ocidSlicesRootArray to (ocidPlistDict's objectForKey:("SlicesRootAttributes"))
if ocidSlicesRootArray = (missing value) then
log "未設定なので設定します"
  set listkMDitem to {"kMDItemKind", "kMDItemLastUsedDate", "kMDItemContentModificationDate", "kMDItemContentCreationDate", "kMDItemDisplayName", "kMDItemTextContent", "com_apple_FileExtensionAttribute", "kMDItemFSInvisible", "kMDItemBitsPerSample", "kMDItemFSName", "kMDItemFSSize", "kMDItemPixelCount", "kMDItemOrientation", "kMDItemDurationSeconds", "kMDItemPixelWidth", "kMDItemPixelHeight", "kMDItemFSLabel", "kMDItemMediaTypes", "kMDItemColorSpace", "kMDItemFonts", "kMDItemPageWidth", "kMDItemFSContentChangeDate", "kMDItemFSCreationDate", "kMDItemEmailAddresses", "kMDItemPageHeight", "kMDItemFSNodeCount", "kMDItemLayerNames"} as list
  set ocidSlicesRootArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidSlicesRootArray's setArray:(listkMDitem)
ocidPlistDict's setObject:(ocidSlicesRootArray) forKey:("SlicesRootAttributes")
else
  ###項目の有無確認 ラベル追加
  set strTBID to ("kMDItemFSLabel") as text
  set boolValue to ocidSlicesRootArray's containsObject:(strTBID)
  if boolValue = false then
log "未設定なので設定します"
    set ocidSetValue to refMe's NSString's stringWithString:(strTBID)
ocidSlicesRootArray's addObject:(ocidSetValue)
  else
log "すでに設定済み"
  end if
end if
###項目の有無確認 タグ追加
set strTBID to ("kMDItemUserTags") as text
set boolValue to ocidSlicesRootArray's containsObject:(strTBID)
if boolValue = false then
log "未設定なので設定します"
  set ocidSetValue to refMe's NSString's stringWithString:(strTBID)
ocidSlicesRootArray's addObject:(ocidSetValue)
else
log "すでに設定済み"
end if
##########################################
####【4】保存 ここは上書き
set boolDone to ocidPlistDict's writeToURL:(ocidPlistFilePathURL) atomically:true
-->システムファイルなの書き込めないので書き込み失敗でfalseが返る
log boolDone


##########################################
####【5】リロード

if boolDone = true then
  tell application "Finder" to quit
  repeat 1 times
delay 1
    #####CFPreferencesを再起動
    set strCommandText to "/usr/bin/killall cfprefsd" as text
do shell script strCommandText
delay 1
  end repeat
  
  tell application "Finder" to activate
return "正常終了"
else
return "保存に失敗しました"
end if



return "処理終了"

|

Finder Windowの保存と復帰

ダウンロード - finderwindow.zip


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
# FinderWindowの保存
#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()
###設定ファイル保存先 Application Support
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidApplicatioocidupportDirPathURL to ocidURLsArray's firstObject()
set ocidSaveDirPathURL to ocidApplicatioocidupportDirPathURL's URLByAppendingPathComponent:("com.cocolog-nifty.quicktimer/Finder")
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
###設定ファイル
set ocidJsonFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("com.apple.finder.every.window.json")
###JSON格納用のArray
set ocidWindowArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
###ウィンドウを格納
tell application "Finder"
  set listEveryWindow to every window as list
end tell
##格納したWINDOWの数だけ々
repeat with itemWindow in listEveryWindow
  ###WINDOWのプロパティを取得して
  tell application "Finder"
    tell itemWindow
      set listBounds to bounds as list
      set listPosition to position as list
      set strViewName to current view as text
      set numSidebarWidth to sidebar width as integer
      set boolToolbar to toolbar visible as boolean
      set boolStatusbar to statusbar visible as boolean
      set boolPathbar to pathbar visible as boolean
      set boolCollapsed to collapsed as boolean
      set aliasTarget to target as alias
    end tell
  end tell
  set strDirPath to (POSIX path of aliasTarget) as text
  set ocidDirPathStr to (refMe's NSString's stringWithString:(strDirPath))
  set ocidDirPath to ocidDirPathStr's stringByStandardizingPath()
  set strDirPath to (ocidDirPath) as text
  ###DICTに保存していく
  set ocidFinderWindowDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidFinderWindowDict's setValue:(listBounds) forKey:("bounds"))
(ocidFinderWindowDict's setValue:(listPosition) forKey:("position"))
(ocidFinderWindowDict's setValue:(strViewName) forKey:("current view"))
(ocidFinderWindowDict's setValue:(numSidebarWidth) forKey:("sidebar width"))
(ocidFinderWindowDict's setValue:(boolToolbar) forKey:("toolbar visible"))
(ocidFinderWindowDict's setValue:(boolStatusbar) forKey:("statusbar visible"))
(ocidFinderWindowDict's setValue:(boolPathbar) forKey:("pathbar visible"))
(ocidFinderWindowDict's setValue:(boolCollapsed) forKey:("collapsed"))
(ocidFinderWindowDict's setValue:(strDirPath) forKey:("target"))
(ocidWindowArray's addObject:(ocidFinderWindowDict))
  
end repeat

### NSJSONSerialization's
set ocidOption to (refMe's NSJSONWritingPrettyPrinted)
set listJsonStrings to refMe's NSJSONSerialization's dataWithJSONObject:(ocidWindowArray) options:(ocidOption) |error|:(reference)
set ocidJsonStrings to item 1 of listJsonStrings
### writeToURL
set ocidOption to (refMe's NSDataWritingAtomic)
set listDone to ocidJsonStrings's writeToURL:(ocidJsonFilePathURL) options:(ocidOption) |error|:(reference)




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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
# Finder Windowの復帰
#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()
###設定ファイル保存先 Application Support
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidApplicatioocidupportDirPathURL to ocidURLsArray's firstObject()
set ocidSaveDirPathURL to ocidApplicatioocidupportDirPathURL's URLByAppendingPathComponent:("com.cocolog-nifty.quicktimer/Finder")
###設定ファイル
set ocidJsonFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("com.apple.finder.every.window.json")
#
set ocidJsonFilePath to ocidJsonFilePathURL's |path|()
set boolDirExists to appFileManager's fileExistsAtPath:(ocidJsonFilePath) isDirectory:(false)
if boolDirExists is false then
return "設定ファイルが見つかりません"
end if
#テキストファイルとして読み込み
set listReadJsonStrings to refMe's NSString's stringWithContentsOfURL:(ocidJsonFilePathURL) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
set ocidJsonStrings to item 1 of listReadJsonStrings
#JSONにして
set ocidJsonData to ocidJsonStrings's dataUsingEncoding:(refMe's NSUTF8StringEncoding)
##Arrayとして取得する
set ocidOption to (refMe's NSJSONReadingMutableContainers)
set listWindowArray to refMe's NSJSONSerialization's JSONObjectWithData:(ocidJsonData) options:(ocidOption) |error|:(reference)
set ocidWindowArray to item 1 of listWindowArray
###取得した数だけ繰り返し
repeat with itemWindowDict in ocidWindowArray
  ##DICTを取得して
  set ocidWindowDict to itemWindowDict
  ##値を取り出して
  set strDirPath to (ocidWindowDict's valueForKey:("target")) as text
  set aliasDirPath to (POSIX file strDirPath) as alias
  set listBounds to (ocidWindowDict's valueForKey:("bounds")) as list
  set listPosition to (ocidWindowDict's valueForKey:("position")) as list
  set strViewName to (ocidWindowDict's valueForKey:("current view")) as text
  set numSidebarWidth to (ocidWindowDict's valueForKey:("sidebar width")) as integer
  set boolToolbar to (ocidWindowDict's valueForKey:("toolbar visible")) as boolean
  set boolStatusbar to (ocidWindowDict's valueForKey:("statusbar visible")) as boolean
  set boolPathbar to (ocidWindowDict's valueForKey:("pathbar visible")) as boolean
  set boolCollapsed to (ocidWindowDict's valueForKey:("collapsed")) as boolean
  ##新規WINDOWで↑の値を設定する
  tell application "Finder"
    set objNewWindow to (make new Finder window to folder aliasDirPath)
    tell objNewWindow
      set bounds to listBounds
      set position to listPosition
      if strViewName contains "list" then
        set current view to list view
      else if strViewName contains "icon" then
        set current view to icon view
      else if strViewName contains "column" then
        set current view to column view
      else if strViewName contains "flow" then
        set current view to flow view
      end if
      set sidebar width to numSidebarWidth
      set toolbar visible to boolToolbar
      set statusbar visible to boolStatusbar
      set pathbar visible to boolPathbar
      set collapsed to boolCollapsed
    end tell
  end tell
  
end repeat





|

[自分用]ローカルファイルをhttp://localhostで開く

ダウンロード - openlocalapache.zip


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

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

property refMe : a reference to current application
##使わなかった…苦笑
property strServerRootPath : "/Library/WebServer/Documents" as text
property strHostURL : "http://localhost" as text

on run
  #############################
  ###ダイアログ
  tell current application
    set strName to name as text
  end tell
  ####スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  ############ デフォルトロケーション
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSLocalDomainMask))
  set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
  set ocidDefaultLocationDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("WebServer/Documents")
  set aliasDefaultLocation to (ocidDefaultLocationDirPathURL's absoluteURL()) as alias
  ###ANY
  set listUTI to {"public.item", "public.html"}
  set strMes to ("ファイルを選んでください") as text
  set strPrompt to ("ファイルを選んでください") as text
  try
    ### ファイル選択時
    set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
  on error
    log "エラーしました"
return "エラーしました"
  end try
open aliasFilePath as alias
end run


on open (argAliasFilePath)
  set strFilePath to (POSIX path of argAliasFilePath) as text
  ##ユーザーディレクトリ配下か?判定用
  set ocidUserName to refMe's NSUserName()
  set strUserName to ocidUserName as text
  ##パスをリストにする
  ##ローカルサイトの場合
  set AppleScript's text item delimiters to "/"
  set listPath to every text item of strFilePath as list
  set AppleScript's text item delimiters to ""
  ##リストの数えて
  set numCntListItem to count of item of listPath
  
  if (strFilePath) contains (strUserName) then
    ##ユーザーサイトの場合
    ##オフセット値 / Users / ユーザー名 / Sites / で5
    set numOffset to numCntListItem - (numCntListItem - 5) as integer
    ##
    set listOpenPathItem to (items (numOffset) thru (last item) of listPath) as list
    set strOpenPath to ("") as text
    repeat with itemPath in listOpenPathItem
      set strOpenPath to (strOpenPath & "/" & itemPath) as text
    end repeat
    set strOpenURL to (strHostURL & "/" & strUserName & strOpenPath) as text
    
  else if (strFilePath) contains ("Shared") then
    ##共有サイトの場合
    ##オフセット値 / Users / Shared / Sites / で5
    set numOffset to numCntListItem - (numCntListItem - 5) as integer
    ##
    set listOpenPathItem to (items (numOffset) thru (last item) of listPath) as list
    set strOpenPath to ("") as text
    repeat with itemPath in listOpenPathItem
      set strOpenPath to (strOpenPath & "/" & itemPath) as text
    end repeat
    set strOpenURL to (strHostURL & "/" & "Shared" & strOpenPath) as text
    
  else
    ##ローカルドキュメントの場合
    ##オフセット値 / Library / WebServer / Documents / で5
    set numOffset to numCntListItem - (numCntListItem - 5) as integer
    ##
    set listOpenPathItem to (items (numOffset) thru (last item) of listPath) as list
    set strOpenPath to ("") as text
    repeat with itemPath in listOpenPathItem
      set strOpenPath to (strOpenPath & "/" & itemPath) as text
    end repeat
    set strOpenURL to (strHostURL & strOpenPath) as text
    
  end if
  log strOpenURL
  tell application "Finder"
    open location strOpenURL
  end tell
  
end open


|

デスクトップを表示非表示


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

#!/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 objFileManager to refMe's NSFileManager's defaultManager()

#####設定項目
set strPlistFileName to "com.apple.finder.plist" as text

##############################################
## ファイルパス関連
##############################################
set listUserLibraryPath to (objFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidFilePathURL to item 1 of listUserLibraryPath
####ファイル名を付与したURL
set ocidFilePathURL to ocidFilePathURL's URLByAppendingPathComponent:"Preferences"
set ocidFilePathURL to ocidFilePathURL's URLByAppendingPathComponent:strPlistFileName
##############################################
## 本処理
##############################################
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
####ファイル読み込み
set listReadPlistData to refMe's NSMutableDictionary's dictionaryWithContentsOfURL:ocidFilePathURL |error|:(reference)
set ocidPlistDict to item 1 of listReadPlistData
##エラー処理
set ocidNSErrorData to item 2 of listReadPlistData
if ocidNSErrorData is not (missing value) then
doGetErrorData(ocidNSErrorData)
end if

##############################################
## Plistの種類を調べる
##############################################

##set boolBin to (refNSPropertyListSerialization's propertyList:ocidPlistDict isValidForFormat:(refMe's NSPropertyListBinaryFormat_v1_0))
##set boolXML to (refNSPropertyListSerialization's propertyList:ocidPlistDict isValidForFormat:(refMe's NSPropertyListXMLFormat_v1_0))
set boolOpen to (refMe's NSPropertyListSerialization's propertyList:ocidPlistDict isValidForFormat:(refMe's NSPropertyListOpenStepFormat))

if boolOpen is true then
return "読み込んだデータのフォーマットが不正です-->OPEN STEP形式です"
end if

set ocidNSbplist to refMe's NSPropertyListBinaryFormat_v1_0

##############################################
##現在の値を取得する
##############################################
-->false
set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue
-->true
set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue

set boolNumber to ocidPlistDict's valueForKey:"CreateDesktop"

if boolNumber = ocidTrue then
  log "現在の値はTRUE=1です"
else if boolNumber = ocidFalse then
  log "現在の値はFALSE=0です"
else
  log "値を取得できませんでした"
end if
##############################################
## 今の設定内容と逆のことを実行する
##############################################
set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/FinderIcon.icns" as alias

if boolNumber = ocidTrue then
  display dialog "デスクトップのアイコンを隠します" with icon aliasIconPath
  
else if boolNumber = ocidFalse then
  display dialog "デスクトップのアイコンを表示します" with icon aliasIconPath
  
end if
##############################################
##現在の値の逆の値をセットする
##############################################
if boolNumber = ocidTrue then
  log "現在の値はTRUE=1です-->FALSE=0をセットします"
ocidPlistDict's setObject:ocidFalse forKey:"CreateDesktop"
else if boolNumber = ocidFalse then
  log "現在の値はFALSE=0です-->TRUE=1をセットします"
ocidPlistDict's setObject:ocidTrue forKey:"CreateDesktop"
else
  log "値を取得できませんでした-->Key を作ってTRUE=1をセットします"
ocidPlistDict's setObject:ocidTrue forKey:"CreateDesktop"
end if
####変更後の値
log (ocidPlistDict's valueForKey:"CreateDesktop") as boolean

##############################################
## ファイルを書き込みます
##############################################

###書き込み用にバイナリーデータに変換
set ocidPlistEditDataArray to refMe's NSPropertyListSerialization's dataWithPropertyList:ocidPlistDict format:ocidNSbplist options:0 |error|:(reference)
set ocidPlistEditData to item 1 of ocidPlistEditDataArray
##エラー処理
set ocidNSErrorData to item 2 of ocidPlistEditDataArray
if ocidNSErrorData is not (missing value) then
doGetErrorData(ocidNSErrorData)
end if

####書き込み
set boolWritetoUrlArray to ocidPlistEditData's writeToURL:ocidFilePathURL options:0 |error|:(reference)
log item 2 of boolWritetoUrlArray

set ocidNSErrorData to item 2 of boolWritetoUrlArray
if ocidNSErrorData is not (missing value) then
doGetErrorData(ocidNSErrorData)
end if

##############################################
## Finder再起動
##############################################
set ocidAppList to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:"com.apple.finder"
if (count of ocidAppList) ≠ 0 then
  ###Finderを取得して
  set ocidAppFinder to ocidAppList's objectAtIndex:0
  ####終了させて
ocidAppFinder's terminate()
  ###2秒まって
  delay 2
  ###起動させる
  set ocidNewFinderApp to refMe's NSWorkspace's sharedWorkspace()
ocidNewFinderApp's launchAppWithBundleIdentifier:"com.apple.finder" options:(refMe's NSWorkspaceLaunchDefault) additionalEventParamDescriptor:(missing value) launchIdentifier:(missing value)
else if (count of ocidAppList) = 0 then
  ###Finderが無いなら起動
  set ocidNewFinderApp to refMe's NSWorkspace's sharedWorkspace()
ocidNewFinderApp's launchAppWithBundleIdentifier:"com.apple.finder" options:(refMe's NSWorkspaceLaunchDefault) additionalEventParamDescriptor:(missing value) launchIdentifier:(missing value)
end if
#############起動確認 10回10秒間
repeat 10 times
  set ocidAppList to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:"com.apple.finder"
  if (count of ocidAppList) = 0 then
    ###Finderが無いなら起動
    set ocidNewFinderApp to refMe's NSWorkspace's sharedWorkspace()
ocidNewFinderApp's launchAppWithBundleIdentifier:"com.apple.finder" options:(refMe's NSWorkspaceLaunchDefault) additionalEventParamDescriptor:(missing value) launchIdentifier:(missing value)
  else
    ###あるなら起動確認終了
    exit repeat
  end if
  delay 1
end repeat



##############################################
## エラー発生時のログ用
##############################################


to doGetErrorData(ocidNSErrorData)
  #####個別のエラー情報
  log "エラーコード:" & ocidNSErrorData's code() as text
  log "エラードメイン:" & ocidNSErrorData's domain() as text
  log "Description:" & ocidNSErrorData's localizedDescription() as text
  log "FailureReason:" & ocidNSErrorData's localizedFailureReason() as text
  log ocidNSErrorData's localizedRecoverySuggestion() as text
  log ocidNSErrorData's localizedRecoveryOptions() as text
  log ocidNSErrorData's recoveryAttempter() as text
  log ocidNSErrorData's helpAnchor() as text
  set ocidNSErrorUserInfo to ocidNSErrorData's userInfo()
  set ocidAllValues to ocidNSErrorUserInfo's allValues() as list
  set ocidAllKeys to ocidNSErrorUserInfo's allKeys() as list
  repeat with ocidKeys in ocidAllKeys
    if (ocidKeys as text) is "NSUnderlyingError" then
      log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s localizedDescription() as text
      log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s localizedFailureReason() as text
      log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s localizedRecoverySuggestion() as text
      log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s localizedRecoveryOptions() as text
      log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s recoveryAttempter() as text
      log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s helpAnchor() as text
    else
      ####それ以外の値はそのままテキストで読める
      log (ocidKeys as text) & ": " & (ocidNSErrorUserInfo's valueForKey:ocidKeys) as text
    end if
  end repeat
  
end doGetErrorData

|

より以前の記事一覧

その他のカテゴリー

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