●メニューへ ●単福へ ●自動車の維持費をシミュレーション ●InDesign JavaScript ノート

AppleScript/ASCII コードで指定


ASCII character (10)

ASCII number "A"


TOPへ


AppleScript/File出力


open for access file FileName with write permission
write TexData to file FileName
close access file FileName


TOPへ


AppleScript/File入力


open for access file FileName
read file FileName
set TexData to result
close access file FileName


TOPへ


AppleScript/SORT


on SORT(myList)
	set myCount to count items of myList
	repeat
		set myFLG to false
		repeat with N from 1 to myCount - 1
			set buf1 to item N of myList
			set buf2 to item (N + 1) of myList
			if buf1 < buf2 then
				set item N of myList to buf2
				set item (N + 1) of myList to buf1
				set myFLG to true
			end if
		end repeat
		if myFLG is false then
			exit repeat
		end if
	end repeat
	return myList
end SORT


TOPへ


AppleScript/countFields


on countFields(myStr, sep)
	set OriginalDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {sep}
	set myStr to text items of myStr
	return count myStr
end countFields

myStrをsep区切りで項目数を返す


TOPへ


AppleScript/delimitersを使って検索置換


set OriginalDelimiters to AppleScript's text item delimiters
	
	set KEN to return --検索文字
	set TIKAN to "" --置換文字
	set AppleScript's text item delimiters to {KEN}
	set TexData to text items of TexData
	set AppleScript's text item delimiters to {TIKAN}
	set TexData to TexData as string
	
	set AppleScript's text item delimiters to OriginalDelimiters

on replaceAll(motoStr, FindStr, repStr)
	set OriginalDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {FindStr}
	set motoStr to text items of motoStr
	set AppleScript's text item delimiters to {repStr}
	set motoStr to motoStr as string
	set AppleScript's text item delimiters to OriginalDelimiters
	return motoStr
end replaceAll


TOPへ


AppleScript/nthFields


on nthFields(myStr, sep, num)
	set OriginalDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {sep}
	set myStr to text items of myStr
	set AppleScript's text item delimiters to OriginalDelimiters
	return item num of myStr
end nthFields

myStrをsep区切りでnum番目の項目を返す


TOPへ


AppleScript/クリップボード


set the clipboard to "123"


set myTable to the clipboard


TOPへ


AppleScript/フォルダ選択OSX


set myFol to choose folder with prompt "フォルダを選択"
set myFol to myFol as string
set myPage to 1
repeat with myFile in list folder myFol without invisibles
	set this_item to (myFol & myFile) as alias
	set FType to file type of (info for this_item)
	if FType is "EPSF" then
		my setEPS(myPage, myFol & myFile, 3)
	else
		
	end if
	set myPage to myPage + 1
end repeat

on setEPS(myPage, inputFile, NURI)
--ここに処理
end setEPS


TOPへ


Finder/Fileタイプ変更のドロップレット


on open inputList
	tell application "Finder"
		repeat with inputFile in inputList
			my getMyFolder(inputFile)
		end repeat
	end tell
end open

on run
	set myFolder to choose file with prompt "ファイルを選択してください"
	my getMyFolder(myFolder)
end run

on getMyFolder(myFolder)
	tell application "Finder"
		set creator type of myFolder to "ART5" --"YoED"
		--set file type of myFolder to "TEXT" --"YoED"
	end tell
end getMyFolder

--★Illustrator
--set creator type of myFolder to "ART5"
--set file type of myFolder to "TEXT"
--★QXP
--set creator type of myFolder to "XPRa"
--set file type of myFolder to "XDOC"
--★mi
--set creator type of myFolder to "MMKE"
--set file type of myFolder to "TEXT"
--★Excel
--set creator type of myFolder to "XCEL"
--set file type of myFolder to "XLS8"
--★Word
--set creator type of myFolder to "MSWD"
--set file type of myFolder to "W8BN"
--★REALbasic
--set creator type of myFolder to "RBv2"
--set file type of myFolder to "RbBF"
--★Application--set file type of myFolder to "APPL"


TOPへ


Finder/commentにファイル名を書き込む


on open inputList
	tell application "Finder"
		repeat with inputFile in inputList
			set comment of inputFile to name of inputFile
		end repeat
	end tell
end open


TOPへ


Finder/アクセス権変更


on run
	set curItem to choose folder with prompt "フォルダを選択"
	my chmod777(curItem)
end run

on open theList
	repeat with curItem in theList
		my chmod777(curItem)
	end repeat
end open

on chmod777(curItem)
	set myPath to POSIX path of curItem
	set cmdStr to "chmod -R 777 " & myPath
	do shell script cmdStr
end chmod777


TOPへ


Finder/スクリプトメニューのインストール


Applications
=>AppleScript
=>Install Script Menu
をダブルクリックする。


TOPへ


Finder/ファイルのコピー


set downFolder to choose folder with prompt "収集するフォルダを選択してください。"
tell application "Finder"
	duplicate alias "Macintosh HD:gazou:PAK2:001111" to downFolder with replacing
end tell

 with replacingで上書きコピー
 with replacingをつけないと上書きコピーされない
同じ名前のファイルがあるとエラーでストップ


TOPへ


Finder/起動中のアプリケーションを調べる


tell application "Finder"
	set OriginalDelimiters to AppleScript's text item delimiters
	--現在のdelimiters設定を保存しておく。
	set AppleScript's text item delimiters to {tab}
	set PROSESS_LIST to (name of every application process)
	set TexData to PROSESS_LIST as string
	--すべての起動しているアプリケーションのリストをPROSESS_LISTへ
	set AppleScript's text item delimiters to OriginalDelimiters
	--必ずdelimiters設定を戻しておく。
	--display dialog TexData
end tell


TOPへ


エラー処理/タイムアウト


with timeout of 1 second
処理
end timeout


TOPへ


エラー処理/処理をストップする


delay 5


TOPへ


フォルダアクション/ドロップされたファイルを処理


on adding folder items to this_folder after receiving added_items
	try
		tell application "Finder"
			--↓フォルダアクションの設定されているフォルダ
			set the folder_name to the name of this_folder
		end tell
		--set the item_count to the number of items in the added_items
		--↓フォルダにドロップされたファイル
		repeat with myFile in added_items
			tell application "Finder"
				set the file_name to the name of myFile
			end tell
			display dialog folder_name & "内の" & file_name
		end repeat
	end try
end adding folder items to


TOPへ


フォルダアクション/設定方法


作成したスクリプトは
Library=>Scripts=>Folder Action Scripts
に入れておく

スクリプトメニューから
Folder Actions=>Attach Script to Folder
を選ぶ

使用するスクリプトを選ぶ

フォルダアクションを設定したいフォルダを選ぶ


TOPへ