[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
| 固定リンク
「NSFileManager」カテゴリの記事
- [com.apple.shortcuts.mac-helper] macOS15.3.1での変更点(NSFileManager temporaryDirectoryの戻り値が変わる場合がある)(2025.02.14)
- ファイルのある親フォルダ名をファイル名にする(2024.09.13)
- [contentsOfDirectoryAtURL]コンテンツURLの収集 第一階層のみ(2024.09.02)
- [Skitch]キャッシュをゴミ箱に入れる(2023.11.11)
- [NSFileManager]ファイルのコピー (Acrobatのスタンプデータのバックアップを作成する)(2023.10.20)
「Attributes」カテゴリの記事
- メタ情報の取得(テキストファイルに出力してテンポラリー保存する簡易版)(2025.04.29)
- [NSFileExtendedAttributes]ファイルの拡張属性をまとめて削除(2025.03.14)
- [xattr]アプリケーション "XXX.app"を開けません。 が出ちゃったら(2025.03.11)
- [com.apple.metadata]xattrでkMDItemWhereFromsダウンロード時のURLの取得(2024.12.12)
- com.apple.TextEncodingの値を再設定する(2024.09.21)