« [Folder]フォルダを開く | トップページ | [moveItemAtURL]フォルダの移動 »

[NSURLIsUserImmutableKey]フォルダをロックする

#!/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 listBoolMakeDir to objFileManager's createDirectoryAtURL:(ocidFilePathURL) withIntermediateDirectories:true attributes:(missing value) |error|:(reference)


set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue

set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue


#####ロックする

ocidFilePathURL's setResourceValue:ocidTrue forKey:(refMe's NSURLIsUserImmutableKey) |error|:(reference)


####ロックを解除する

ocidFilePathURL's setResourceValue:ocidFalse forKey:(refMe's NSURLIsUserImmutableKey) |error|:(reference)




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

#####日付

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

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


|

« [Folder]フォルダを開く | トップページ | [moveItemAtURL]フォルダの移動 »

AppleScript Folder」カテゴリの記事