正規表現じゃないならAppleScript's text item delimitersでできそう。
on replaceText(inText, inOld, inNew) set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {inOld} set workData to text items of inText set AppleScript's text item delimiters to {inNew} set workData to workData as string set AppleScript's text item delimiters to OriginalDelimiters return workData end replaceText set theText to my replaceText("名称未設定OSX.txt", "OSX", "OS9")
>>152ありがとうございます。 on replaceText(inText, inOld, inNew)は使い方がよく分からなかったので (なんかドロップレットの中で使うと?エラーがでます) ↓結局こうなりました。
set kara to text item delimiters of AppleScript set motonamae to name of hensuu set text item delimiters of AppleScript to sakujo set sakujogonamae to (every text item of motonamae) set text item delimiters of AppleScript to tuika set name of hensuu to sakujogonamae as string set text item delimiters of AppleScript to kara
tell application "Finder" set myFinderSelection to selection repeat with I in myFinderSelection tell application "DropStuff" to stuff (I as alias) format StuffIt to my myGetDesktopFolder() end repeat end tell
on myGetDesktopFolder() tell application "Finder" return (desktop as alias) end tell end myGetDesktopFolder
open for access で delimiterをascii character 12にしてリストとして読み、 as textでテキスト変換するとか。あるいは伝統的手法でAppeScript's text item delimitersを ascii character 12にするとかやろうとしたけど、これっ てなんかうまくいかないね。
on open dropItems tell application "Finder" repeat with anItem in dropItems set theName to name of anItem if theName ends with ".tar.gz" then set name of anItem to my replace(theName, ".tar.gz", ".tgz") else if name of anItem ends with ".tar.bz2" then set name of anItem to my replace(theName, ".tar.bz2", ".tbz") end if end repeat end tell end open to replace(theText, replaceStr1, replaceStr2) set oldDel to AppleScript's text item delimiters set AppleScript's text item delimiters to replaceStr1 set theText to every text item of theText set AppleScript's text item delimiters to replaceStr2 set theText to theText as string set AppleScript's text item delimiters to oldDel return theText end replace
リストを逆順で処理するのは>185の一部をかえる場合次のようにする repeat with theIndex from (count (dropItems)) to 1 by -1 set anItem to item theIndex of dropItems display alert anItem end repeat あとはiTunesで開けばいいんじゃないかな?
on maxSort(aList) copy aList to theList set sum to count theList repeat with i from 1 to sum - 1 repeat with j from i + 1 to sum if item i of theList > item j of theList then set temp to item i of theList set item i of theList to item j of theList set item j of theList to temp end if end repeat end repeat return theList end maxSort
set oldDelims to AppleScript's text item delimiters set AppleScript's text item delimiters to {ASCII character 10} set listString to (theList as string) set newString to do shell script "echo " & quoted form of listString & " | sort -f" set newList to (paragraphs of newString) set AppleScript's text item delimiters to crlfStr set newString to (newList as string) set AppleScript's text item delimiters to oldDelims
Finderでselectionを使うとき、name of selection ってすると、選択してるファイルの 名前がリストで返ってきますよね? でも、selectionを変数に入れて name of my_sel とかってするとエラーが出ます、よね? あと、name of (item 1 of my_sel) や、name of (item 1 of selection) は、両方ちゃんと ファイル名を取得できますが、name of (every item of my_sel) は、 name of (every item of selection) と違って、エラーが出ます・・・よね?
"Show Raw File" 01 tell application "iPhoto" activate try copy (my selected_images()) to these_images if these_images is false or (the count of these_images) is not 1 then error "一個づつしか調べきらんと" set this_image to item 1 of these_images set textName to (image filename of this_image) as text set textName to my replaceW(textName, ".jpg", ".nef") set textPath to (image path of this_image) as text set textDate to (date of this_image) as text set oldDel to AppleScript's text item delimiters set AppleScript's text item delimiters to " " set textDate to text item 1 of textDate set textDate to my replaceW(textDate, "-", "/") set AppleScript's text item delimiters to "/" set libraryName to text item ((count text item of textPath) - 4) of textPath set AppleScript's text item delimiters to libraryName set textPath to text item 1 of textPath set AppleScript's text item delimiters to oldDel set textPath to textPath & libraryName & "/" & textDate & "/Originals/" & textName
--"Show Raw File"02 try set this_imagefile to ((textPath) as POSIX file) as alias on error try set changePath to text item ((count item of textPath) - 5) of textPath & text item ((count item of textPath) - 4) of textPath & ".nef" set textPath to my replaceW(textPath, changePath, ".nef") set this_imagefile to ((textPath) as POSIX file) as alias on error display dialog "RAWファイルじゃなかろごたぁ" end try end try
on error error_message number error_number if the error_number is not -128 then display dialog error_message buttons {"Cancel"} default button 1 end if end try end tell
--"Show Raw File"03 tell application "Finder" activate set visible of (every process whose visible is true and frontmost is false) to false reveal this_imagefile end tell
on selected_images() tell application "iPhoto" try set these_items to the selection if the class of item 1 of these_items is album then error return these_items on error return false end try end tell end selected_images
on replaceW(src, tg, rp) set oldDel to AppleScript's text item delimiters set AppleScript's text item delimiters to tg set myList to text items of src set AppleScript's text item delimiters to rp set myText to myList as string set AppleScript's text item delimiters to oldDel return myText end replaceW
tell application "Mail" set selectedMails to selection set msg to item 1 of selectedMails set subj to subject of msg set mid to id of msg end tell
set mailURL to do shell script "mdfind -onlyin ~/Library/Mail 'kMDItemFSName == ¥"" & mid & ".emlx¥"'|head -1"
set mailURL to "file://" & mailURL
tell application "iCal" activate tell calendar 1 set theEv to make event at end of every event with properties {summary:subj, start date:current date, end date:(current date) + 3600, url:mailURL} show theEv end tell end tell