« [fig 02-09] フォルダの作成日 修正日 | トップページ | [Basic]リスト形式色々 »

[fig 02-09]フォルダ内のアイテム

指定フォルダ内に内包される項目
例はユーザーの音楽Musicフォルダ


tell application "Finder"
tell folder (path to music folder from user domain)
set file_list to name of every item
end tell
end tell


#!/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 ocidUserMusicPath to (objFileManager's URLsForDirectory:(objMe's NSMusicDirectory) inDomains:(objMe's NSUserDomainMask))
log ocidUserMusicPath as list
log ocidUserMusicPath as text

####UNIXパス形式に変換(NSSingleObjectArraytringで確定させる)
set ocidFileRelativePath to (ocidUserMusicPath's objectAtIndex:0)'s relativePath
log ocidFileRelativePath as text
log className() of ocidFileRelativePath as text

###NSStringにして
set ocidDirPath to objNSString's stringWithString:ocidFileRelativePath
log ocidDirPath as text
log className() of ocidDirPath as text


###ディレクトリのコンテンツ一覧
set arrayFilesList to objFileManager's contentsOfDirectoryAtPath:ocidDirPath |error|:(missing value)
####
log arrayFilesList
log arrayFilesList's className() as text
log arrayFilesList as list

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

|

« [fig 02-09] フォルダの作成日 修正日 | トップページ | [Basic]リスト形式色々 »

AppleScript Guide」カテゴリの記事

AppleScript NSWorkspace」カテゴリの記事