« [moveItemAtPath]リネーム | トップページ | [fileExistsAtPath]フォルダの有無 »

[copyItemAtPath]ファイルのコピー

#!/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 objMe : a reference to current application
property objNSString : a reference to objMe's NSString
set objFileManager to objMe's NSFileManager's defaultManager()

#####テキストの内容
###現在使用中のフォアグラウンドアプリケーション名一覧
tell application "System Events"
set listAppList to name of (processes where background only is false)
end tell
set strAppList to ""
repeat with objAppList in listAppList
set strAppName to objAppList as text
set strAppList to (strAppList & strAppName & "\n") as text
end repeat

###NSStringテキスト
set objAppList to objNSString's stringWithString:strAppList

######################
###フォルダのパス
###デスクトップフォルダのパス
set aliasDirPath to (path to desktop folder from user domain) as alias
set strDirPath to POSIX path of aliasDirPath as text


############################################
##まず最初に作るファイルのファイル名(昨日の日付)
set strDateAndTimeJp to (my dateFormatterWithFormatYesterday:"yyyyMMMMddEEEE")
set strNewFilePath to ("" & strDirPath & strDateAndTimeJp & ".txt") as text
###NSStringテキスト
set objNewFilePath to objNSString's stringWithString:strNewFilePath

###ファイルを作る
set boolMakeNewFile to (objFileManager's createFileAtPath:objNewFilePath |contents|:objAppList attributes:(missing value))
log boolMakeNewFile
###ここでデスクトップにNewFile.txtが出来上がる
####確認するときはRetuneしてみて
#return
###↑で作った昨日の日付ファイルを今日の日付ファイルに『コピー』します
############################################
##コピー用のファイル名(昨日の日付)
set strDateAndTimeJp to (my dateFormatterWithFormat:"yyyyMMMMddEEEE")
set strCopyFilePath to ("" & strDirPath & strDateAndTimeJp & ".txt") as text
###NSStringテキスト
set objCopyFilePath to objNSString's stringWithString:strCopyFilePath

###ファイルをコピ
set boolFileCopy to (objFileManager's copyItemAtPath:objNewFilePath toPath:objCopyFilePath |error|:(missing value))


log boolFileCopy
-->true or false

###日付のサブ 今日
on dateFormatterWithFormat:classDateFormat
set formatter to objMe's NSDateFormatter's alloc()'s init()
formatter's setLocale:(objMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
formatter's setDateFormat:(classDateFormat as string)
set theString to (formatter's stringFromDate:(current date)) as text
end dateFormatterWithFormat:


###日付のサブ 昨日
on dateFormatterWithFormatYesterday:classDateFormat
set formatter to objMe's NSDateFormatter's alloc()'s init()
formatter's setLocale:(objMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
formatter's setDateFormat:(classDateFormat as string)
set theString to (formatter's stringFromDate:((current date) - days)) as text
end dateFormatterWithFormatYesterday:

|

« [moveItemAtPath]リネーム | トップページ | [fileExistsAtPath]フォルダの有無 »

AppleScript NSFileManager」カテゴリの記事