AppleScript NSFileManager

[Skitch]キャッシュをゴミ箱に入れる


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

#!/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 NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
set ocidPrefDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Containers/com.skitch.skitch/Data/tmp")
##コンテンツ収集 1階層のみ
set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
set ocidKeyArray to refMe's NSArray's arrayWithArray:({(refMe's NSURLPathKey), (refMe's NSURLIsDirectoryKey), (refMe's NSURLIsSymbolicLinkKey)})
set listSubPathResult to (appFileManager's contentsOfDirectoryAtURL:(ocidPrefDirPathURL) includingPropertiesForKeys:(ocidKeyArray) options:(ocidOption) |error|:(reference))
set ocidSubPathURLArray to item 1 of listSubPathResult
###収集したURLの数だけ繰り返し
repeat with itemSubPathURL in ocidSubPathURLArray
  ###ゴミ箱に入れる
  set listDone to (appFileManager's trashItemAtURL:(itemSubPathURL) resultingItemURL:(itemSubPathURL) |error|:(reference))
end repeat


|

[NSFileManager]ファイルのコピー (Acrobatのスタンプデータのバックアップを作成する)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
バックアップデータ
1:上書き
2:日付を入れる等して個別データ完全
3:差分のみバックアップする 等がありますが
これは、2の日付を入れた個別データ完全バックアップです
*)
# 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
######################
##書類フォルダ
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDocumentDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDocumentDirPathURL to ocidURLsArray's firstObject()
set ocidMkDirPathURL to ocidDocumentDirPathURL's URLByAppendingPathComponent:("Adobe/Acrobat/Stamps/") isDirectory:(true)
###フォルダを作っておく
###フォルダのアトリビュート
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
set listDone to (appFileManager's createDirectoryAtURL:(ocidMkDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
###保存先となるパス
set strDateNo to doGetDateNo({"yyyyMMdd", 1}) as text
set ocidSaveDirPathURL to (ocidMkDirPathURL's URLByAppendingPathComponent:(strDateNo) isDirectory:(true))
######################
###スタンプフォルダ
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
set ocidDcDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Adobe/Acrobat/DC/") isDirectory:(true)
set ocidStampDirPathURL to (ocidDcDirPathURL's URLByAppendingPathComponent:("Stamps") isDirectory:(true))

######################
###ファイルコピー
set listDone to appFileManager's copyItemAtURL:(ocidStampDirPathURL) toURL:(ocidSaveDirPathURL) |error|:(reference)
### ファイルのコピーに失敗した場合のエラー表示
if (item 1 of listDone) is false then
  set ocidNSErrorData to (item 2 of listDone)
  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
return "コピーに失敗しました"
end if

######################
###保存先を開く
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolDone to appSharedWorkspace's selectFile:(ocidSaveDirPathURL's |path|()) inFileViewerRootedAtPath:(ocidMkDirPathURL's |path|())
###エラーしたらFinderで開く
if boolDone is false then
  set aliasOpenDirPath to (ocidMkDirPathURL's absoluteURL()) as alias
  tell application "Finder"
    open folder aliasOpenDirPath
  end tell
return "エラーしました"
end if



################################
# 日付 doGetDateNo(argDateFormat,argCalendarNO)
# argCalendarNO 1 NSCalendarIdentifierGregorian 西暦
# argCalendarNO 2 NSCalendarIdentifierJapanese 和暦
################################
to doGetDateNo({argDateFormat, argCalendarNO})
  ##渡された値をテキストで確定させて
  set strDateFormat to argDateFormat as text
  set intCalendarNO to argCalendarNO as integer
  ###日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  ###日付のフォーマットを定義(日本語)
  set ocidFormatterJP to current application's NSDateFormatter's alloc()'s init()
  ###和暦 西暦 カレンダー分岐
  if intCalendarNO = 1 then
    set ocidCalendarID to (current application's NSCalendarIdentifierGregorian)
  else if intCalendarNO = 2 then
    set ocidCalendarID to (current application's NSCalendarIdentifierJapanese)
  else
    set ocidCalendarID to (current application's NSCalendarIdentifierISO8601)
  end if
  set ocidCalendarJP to current application's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID)
  set ocidTimezoneJP to current application's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo")
  set ocidLocaleJP to current application's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX")
  ###設定
ocidFormatterJP's setTimeZone:(ocidTimezoneJP)
ocidFormatterJP's setLocale:(ocidLocaleJP)
ocidFormatterJP's setCalendar:(ocidCalendarJP)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterNoStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterShortStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterMediumStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterLongStyle)
ocidFormatterJP's setDateStyle:(current application's NSDateFormatterFullStyle)
  ###渡された値でフォーマット定義
ocidFormatterJP's setDateFormat:(strDateFormat)
  ###フォーマット適応
  set ocidDateAndTime to ocidFormatterJP's stringFromDate:(ocidDate)
  ###テキストで戻す
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo

|

[NSFilePosixPermissions]パーミッション変更10進数

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

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



####ダイアログで使うデフォルトロケーション
tell application "Finder"
  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
end tell

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

set strFilePath to POSIX path of aliasFilePath
####ドキュメントのパスをNSString
set ocidFilePath to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePath's stringByStandardizingPath
set ocidNSUrlPath to refMe's NSURL's fileURLWithPath:ocidFilePath


###アトリビュートを取得
set ocidFileAttr to appFileManager's attributesOfItemAtPath:ocidFilePath |error|:(missing value)
log (ocidFileAttr's valueForKey:"NSFilePosixPermissions") as integer

###8進数パーミッション値を10進数に変換
set strPemission to doOct2Dem(777)
####パス指定でパーミッション変更 10進数指定
appFileManager's setAttributes:{NSFilePosixPermissions:strPemission} ofItemAtPath:ocidFilePath |error|:(reference)

###511になれば777
###アトリビュートを取得
set ocidFileAttr to appFileManager's attributesOfItemAtPath:ocidFilePath |error|:(missing value)
log (ocidFileAttr's valueForKey:"NSFilePosixPermissions") as integer


###################################
#####パーミッション 8進→10進
(*
###主要なモード NSFilePosixPermissions
777-->511
775-->509
770-->504
755-->493
750-->488
700-->448
555-->365
333-->219
*)
###################################

to doOct2Dem(argOctNo)
  set strOctalText to argOctNo as text
  set num3Line to first item of strOctalText as number
  set num2Line to 2nd item of strOctalText as number
  set num1Line to last item of strOctalText as number
  set numDecimal to (num3Line * 64) + (num2Line * 8) + (num1Line * 1)
  return numDecimal as integer
end doOct2Dem

|

[Folder]新しいフォルダを作る

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


property refNSDate : a reference to refMe's NSDate

property refNSCalendar : a reference to refMe's NSCalendar

property refNSTimeZone : a reference to refMe's NSTimeZone

property refNSDateFormatter : a reference to refMe's NSDateFormatter



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





set ocidDesktopDirPathURL to (objFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))


set aliasDefaultLocation to ocidDesktopDirPathURL as alias

set strDefaultName to doGetDateNo("yyyyMMdd") as text

set strPromptText to "名前を決めてください" as text


set aliasPath to (choose file name default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»

####パステキスト

set strFilePathText to POSIX path of aliasPath as text

###String

set ocidFilePath to (refNSString's stringWithString:strFilePathText)

###絶対パスで

set ocidFilePathString to ocidFilePath's stringByStandardizingPath

###NSURL

set ocidFilePathURL to (refNSURL's alloc()'s initFileURLWithPath:ocidFilePathString isDirectory:true)


############################

#####属性を指定しておく

set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0

set numUID to user ID of (system info) as number

###所有者ID

ocidAttrDict's setValue:numUID forKey:(refMe's NSFileOwnerAccountID)

###グループID

ocidAttrDict's setValue:80 forKey:(refMe's NSFileGroupOwnerAccountID)

#####NSFileGroupOwnerAccountID

(* ゲストのGID

80-->admin

20-->staff

201-->_guest

99-->_unknown

-2-->nobody

*)

####パーミッション

set numPermissionDem to doOct2Dem(777) as integer

log numPermissionDem

ocidAttrDict's setValue:numPermissionDem forKey:(refMe's NSFilePosixPermissions)

###作るフォルダの属性

(*

###主要なモード NSFilePosixPermissions

777-->511

775-->509

770-->504

755-->493

750-->488

700-->448

555-->365

333-->219

*)

ocidAttrDict's setValue:(refMe's NSFileProtectionNone) forKey:(refMe's NSFileProtectionKey)

ocidAttrDict's setValue:0 forKey:(refMe's NSFileAppendOnly)


############################

###フォルダを作る

set listBoolMakeDir to objFileManager's createDirectoryAtURL:(ocidFilePathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)


############################

####ラベルを指定する

(*

0:ラベル無し

1:グレー

2:グリーン

3:パープル

4:ブルー

5:イエロー

6:レッド

7:オレンジ

*)

ocidFilePathURL's setResourceValue:7 forKey:(refMe's NSURLLabelNumberKey) |error|:(reference)

############################

####コメントの追加

tell application "Finder" to set comment of item aliasPath to strDefaultName






###################################

#####日付

###################################

to doGetDateNo(strDateFormat)

  ####日付情報の取得

  set ocidDate to refNSDate's |date|()

  ###日付のフォーマットを定義

  set ocidNSDateFormatter to refNSDateFormatter's alloc()'s init()

  ocidNSDateFormatter's setLocale:(refMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")

  ocidNSDateFormatter's setDateFormat:strDateFormat

  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate

  set strDateAndTime to ocidDateAndTime as text

  return strDateAndTime

end doGetDateNo



###################################

#####パーミッション 8進→10進

###################################

to doOct2Dem(argOctNo)

  set strOctalText to argOctNo as text

  set num3Line to first item of strOctalText as number

  set num2Line to 2nd item of strOctalText as number

  set num1Line to last item of strOctalText as number

  set numDecimal to (num3Line * 64) + (num2Line * 8) + (num1Line * 1)

  return numDecimal

end doOct2Dem


|

[trashItemAtURL]フォルダの中身をゴミ箱に入れる

#!/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 aliasDefaultLocation to (path to desktop folder from user domain) as alias
###ダイアログテキスト
set strPromptText to "入力フォルダを選んでください"
try
set listResponse to (choose folder strPromptText with prompt strPromptText default location aliasDefaultLocation without multiple selections allowed, invisibles and showing package contents) as list
on error
log "エラーしました"
return
end try
###エリアス
set aliasDirPath to (item 1 of listResponse) as alias
###UNIXパス
set strFilePathText to POSIX path of aliasDirPath as text

###この指定でもOK
###set strFilePathText to "~/Desktop/名称未設定フォルダ"

###String
set ocidFilePath to (refNSString's stringWithString:strFilePathText)
###絶対パスで
set ocidFilePathString to ocidFilePath's stringByStandardizingPath
###NSURL
set ocidFilePathURL to (refNSURL's alloc()'s initFileURLWithPath:ocidFilePathString isDirectory:true)


###実行
doGo2TrashDirContentsURL(ocidFilePathURL)



################################
####フォルダの中身をゴミ箱へ入れる
################################
on doGo2TrashDirContentsURL(ocidDirUrl)
###ファイルマネージャー初期化
set objFileManager to refMe's NSFileManager's defaultManager()
################################
####渡された値がNSURL以外の場合の処理
try
set strClassName to class of ocidDirUrl as text
####渡された値がテキストだったら
if strClassName is "text" then
set strDirUrl to ocidDirUrl as text
####渡された値がエイリアスだったら
else if strClassName is "alias" then
set strDirPath to POSIX path of ocidDirUrl as text
end if
set ocidFilePath to (refNSString's stringWithString:strDirPath)
set ocidFilePathString to ocidFilePath's stringByStandardizingPath
set ocidDirPathURL to (refNSURL's alloc()'s initFileURLWithPath:ocidFilePathString isDirectory:true)
on error
######ocid形式の値だったら
set strClassName to ocidDirUrl's className() as text
###テキストなら
if strClassName contains "NSCFString" then
set ocidFilePathString to ocidDirUrl's stringByStandardizingPath
set ocidDirPathURL to (refNSURL's alloc()'s initFileURLWithPath:ocidFilePathString isDirectory:true)
###NSURLなら
else if strClassName is "NSURL" then
set ocidDirPathURL to ocidDirUrl
else
error "NSURLを指定してください" number -9999
return
end if
end try
################################
####渡されたパスが無い場合はエラー
set ocidFilePathString to ocidDirPathURL's |path|()
set boolFolderExists to (objFileManager's fileExistsAtPath:ocidFilePathString isDirectory:true)
if boolFolderExists is false then
log "パス先が実在しません"
####パス先ない場合は作っておく
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions)

set listBoolMakeDir to objFileManager's createDirectoryAtURL:(ocidDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
return
end if
################################
####ディレクトリか?の判断 ファイルならエラーで止める
set ocidResultArray to ocidDirPathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference)
if (item 3 of ocidResultArray) is not (missing value) then
doGetErrorData(item 3 of ocidResultArray)
end if
set ocidResultValue to item 2 of ocidResultArray
-->false
set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue
if ocidResultValue is ocidFalse then
##error "パス先がファイルですディレクトリを指定してください" number -9999
log "パス先がファイルですディレクトリを指定してください"
return
end if
##################################
##内包リスト
set listResult to objFileManager's contentsOfDirectoryAtURL:ocidDirPathURL includingPropertiesForKeys:{refMe's NSURLPathKey} options:0 |error|:(reference)
###エラー発生時
if (item 2 of listResult) is not (missing value) then
doGetErrorData(item 2 of listResult)
end if
###結果
set ocidPathArray to item 1 of listResult
repeat with itemPathArray in ocidPathArray
set ocidPathArrayURL to itemPathArray
##ゴミ箱に入れる
set listResult to (objFileManager's trashItemAtURL:ocidPathArrayURL resultingItemURL:(missing value) |error|:(reference))
###エラー発生時
if (item 2 of listResult) is not (missing value) then
doGetErrorData(item 2 of listResult)
end if

end repeat

end doGo2TrashDirContentsURL







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

|

[NSDirectoryEnumerationSkip]enumeratorAtURL:includingPropertiesForKeys:options:XerrorHandler:

enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:
options:の後の数値

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


log refMe's NSDirectoryEnumerationSkipsHiddenFiles as integer
(*4*)
log refMe's NSDirectoryEnumerationSkipsPackageDescendants as integer
(*2*)
log refMe's NSDirectoryEnumerationSkipsSubdirectoryDescendants as integer
(*1*)

|

[NSSearchPath]ユーザーデスクトップフォルダーへのパス

#!/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 refNSArray : a reference to refMe's NSArray
set objFileManager to refMe's NSFileManager's defaultManager()

set ocidDeskTopDirArray to refMe's NSSearchPathForDirectoriesInDomains(refMe's NSDesktopDirectory, refMe's NSUserDomainMask, true)

log className() of ocidDeskTopDirArray as text
-->(*__NSSingleObjectArrayI*)

set strUserDesktopPath to (ocidDeskTopDirArray's firstObject()) as text
set strUserDesktopPath to (ocidDeskTopDirArray's objectAtIndex:0) as text

|

[FileManager]NSDirectoryEnumerationSkipsHiddenFiles(不可視ファイルを除く)

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

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

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSURL : a reference to objMe's NSURL
property objNSArray : a reference to objMe's NSArray
property objNSDirectoryEnumerationSkipsHiddenFiles : a reference to objMe's NSDirectoryEnumerationSkipsHiddenFiles
property objNSURLNameKey : a reference to objMe's NSURLNameKey


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

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


set strDirPath to "/Users/Shared/Relocated Items"

##Make NSString
set ocidNSString to objNSString's stringWithString:strDirPath
log ocidNSString as text
log ocidNSString's className() as text

set ocidURLPath to objNSURL's fileURLWithPath:ocidNSString
log ocidURLPath as text
log ocidURLPath's className() as text

set ocidFileFile to objFileManager's contentsOfDirectoryAtURL:ocidURLPath includingPropertiesForKeys:{objNSURLNameKey} options:objNSDirectoryEnumerationSkipsHiddenFiles |error|:(missing value)


repeat with objFiles in ocidFileFile
log objFiles as text
end repeat




#########################ログ表示
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
tell application "Script Editor"
tell application "System Events"
tell process "Script Editor"
tell window 1
tell splitter group 1
tell splitter group 1
tell group 1
tell checkbox "返された値"
set boolValue to value as boolean
end tell
if boolValue is false then
click checkbox "返された値"
end if
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end if
end repeat

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

|

[FileManager]createDirectoryAtURL:withIntermediateDirectories:attributes:error:

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

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

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSURL : a reference to objMe's NSURL
property objUTType : a reference to objMe's UTType

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

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



###ユーザーアプリケーションフォルダを作る
set ocidUserApplicationsPathList to (objFileManager's URLsForDirectory:(objMe's NSApplicationDirectory) inDomains:(objMe's NSUserDomainMask))
log ocidUserApplicationsPathList as list
log className() of ocidUserApplicationsPathList as text


set ocidUserApplicationsPath to ocidUserApplicationsPathList's objectAtIndex:0
log ocidUserApplicationsPath as list
log className() of ocidUserApplicationsPath as text


set boolMakeNewFolder to (objFileManager's createDirectoryAtURL:ocidUserApplicationsPath withIntermediateDirectories:true attributes:(missing value) |error|:(missing value))
log boolMakeNewFolder as boolean
log class of boolMakeNewFolder


if boolMakeNewFolder is false then
log "フォルダ作成でエラーしました"
error "" number -128
return
end if


#########################ログ表示
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
#########################

|

[NSURL] homeDirectoryForUser

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

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

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSURL : a reference to objMe's NSURL


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

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



set ocidTemporaryDirUrl to objFileManager's homeDirectoryForUser:"admin"
log ocidTemporaryDirUrl as text
log className() of ocidTemporaryDirUrl as text
(*Macintosh HD:Users:admin:*)
(*NSURL*)


set ocidTemporaryDirUrl to objFileManager's temporaryDirectory
log ocidTemporaryDirUrl as text
log className() of ocidTemporaryDirUrl as text
(*Macintosh HD:private:var:folders:XXXXXXX:XXXXXXXXXXXXXXXXXXX:T:*)
(*NSURL*)



#########################ログ表示
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