« [Acrobat JS]ヘルプメニュー 更新 | トップページ | [Folder]フォルダを開く »

[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


|

« [Acrobat JS]ヘルプメニュー 更新 | トップページ | [Folder]フォルダを開く »

AppleScript NSFileManager」カテゴリの記事

AppleScript Folder」カテゴリの記事