« [NSDate] setDateFormat | トップページ | [fig 02-03]フォルダの作成と削除 »

[fig 02-03]フォルダの作成 と 削除

#!/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
####ログ表示
doLogView()
####
property objMe : a reference to current application
property objNSString : a reference to objMe's NSString

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

####ランダム番号を生成
set numRandomNo to (random number 100) as integer
set numRandomNo to (random number from 0 to 100) as integer
set numRandomNo to (random number from 50 to 100) as integer

log numRandomNo
log class of numRandomNo

####フォルダ名を定義
set strFolderName to "番号フォルダ" & numRandomNo as text
log strFolderName as text
log class of strFolderName

#### フォルダ名をNSString
set ocidFolderName to objNSString's stringWithString:strFolderName
log ocidFolderName as text
log className() of ocidFolderName as text

set strDesktopPath to "~/Desktop/"

###ユーザーデスクトップフォルダを定義
set ocidDesktopPath to objNSString's stringWithString:strDesktopPath
log ocidDesktopPath as text
log className() of ocidDesktopPath as text

####フォルダ名を追加して作成するフォルダへのパスにする
set ocidMakeFolderPath to ocidDesktopPath's stringByAppendingString:ocidFolderName
log ocidMakeFolderPath as text
log className() of ocidMakeFolderPath as text

#####パス化する
set ocidPOSIXpath to ocidMakeFolderPath's stringByStandardizingPath
log ocidPOSIXpath as text
log className() of ocidPOSIXpath as text

####フォルダを作成
set boolMakeNewFolder to (objFileManager's createDirectoryAtPath:ocidPOSIXpath withIntermediateDirectories:true attributes:(missing value) |error|:(missing value))
log boolMakeNewFolder as boolean
log class of boolMakeNewFolder


###2秒まって
delay 2

###パスをNSStringに変換
set ocidPOSIXpathNSString to objNSString's stringWithString:ocidPOSIXpath
log ocidPOSIXpathNSString as text
log className() of ocidPOSIXpathNSString as text

###フォルダを削除
set boolGoToTrash to objFileManager's removeItemAtPath:ocidPOSIXpathNSString |error|:(missing value)
log boolGoToTrash as boolean
log class of boolGoToTrash as text

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

|

« [NSDate] setDateFormat | トップページ | [fig 02-03]フォルダの作成と削除 »

AppleScript NSFileManager」カテゴリの記事

AppleScript Guide」カテゴリの記事