on run set dlgReply to (display dialog "Get a Yahoo! stock quote for this symbol:" default answer "AAPL" buttons {"Get Quote"@` "Cancel"} default button 1 giving up after 30) if button returned of dlgReply is "Cancel" then return set daSymbol to allCaps(text returned of dlgReply) -- make a temp file set myFile to ((path to temporary items) as string) & "Stock Quote Script Temp" -- fetch quote page tell application "URL Access Scripting" download "http://finance.yahoo.com/q" to file myFile replacing yes form data "s=" & daSymbol & "&d=v1" quit end tell -- read HTML into a variable open for access file myFile set quoteHTML to (read file myFile to (get eof file myFile)) close access file myFile -- find the lines with the last trade date and last price -- Note: Yahoo changes their HTML format@` this needs to change too. set startTag to daSymbol & "</a></td>" & (ASCII character 10) set daStart to (the offset of startTag in quoteHTML) + (the length of startTag) set daCount to 1 copy "" to lastTrade copy "" to lastPrice repeat if text from character (daStart + daCount) to (daStart + daCount + 1) of quoteHTML is "/t" then if lastTrade is "" then set lastTrade to text from character daStart to (daStart + daCount - 2) of quoteHTML set daStart to daStart + daCount + 5 set daCount to 1 else set lastPrice to text from character daStart to (daStart + daCount - 2) of quoteHTML exit repeat end if end if set daCount to daCount + 1 end repeat -- tell application "Finder" to delete file myFile set lastTrade to stripHTMLTags(lastTrade) if lastTrade contains ":" then -- markets are open@` so it's a time set lastTrade to "at " & lastTrade else -- martets are closed@` so it's a date set lastTrade to "on " & lastTrade end if display dialog "Yahoo says " & daSymbol & " last traded " & lastTrade & " at $" & stripHTMLTags(lastPrice) & "." with icon 1 buttons "OK" default button 1 giving up after 30 end run
on allCaps(daText) -- very messy capitalization routine copy "" to newText repeat with i from 1 to the count of character in daText set curChar to character i of daText set curNum to ASCII number curChar if (curNum > 96) and (curNum < 123) then set newText to (newText & (ASCII character (curNum - 32))) as string else set newText to (newText & curChar) as string end if end repeat return newText end allCaps
on stripHTMLTags(HTML) -- slow@` and fails on bad HTML that doesn't use entities for < and > -- but@` requires no OSAXen and is good enough for now. set intag to false set newText to "" repeat with i from 1 to count of character in HTML set curChar to character i of HTML if curChar is "<" then set intag to true if not intag then set newText to (newText & curChar) as string if curChar is ">" then set intag to false end repeat return newText end stripHTMLTags
---------------------- ここから ------------------ on open theList repeat with x in theList set FilePath to x DownloadGo(FilePath as string) end repeat end open
on run set FilePath to (choose file with prompt "ダウンロードするファイルのURLを記述したファイルを選択してください。")
DownloadGo(FilePath as string) end run
on DownloadGo(FilePath) --設定ファイルを読み込む try open for access file FilePath -- 設定ファイルを開く set LinesBuf to every paragraph of (read file FilePath) -- 行毎に読み込む close access file FilePath -- 設定ファイルを閉じる on error display dialog (FilePath as string) & " が設定されていません" -- エラーだぜ set LinesBuf to "" end try
--ファイル解析 repeat with lineBuf in LinesBuf -- コメントでも空行でも無ければ実行 if (lineBuf does not start with "#") and (number of (every word of lineBuf) > 0) then
--アプリケーションを使ってダウンロード(ここを書き換えれば、他のアプリでもダウンロード可) tell application "iCab" --activate try fetchurl lineBuf -- ダウンロード end try end tell end if
on run tell application "Netscape Communicator (tm)" set currenturl to URL of window 1 end tell tell application "Internet Explorer" Activate OpenURL currenturl end tell end run
--Gooの英和辞書を使う --クリップボードにコピーされている英単語をGooの英和辞書サービスで検索する tell application "Finder" activate (the clipboard) set tango to result as text end tell tell application "Internet Explorer" OpenURL "http://dictionary.goo.ne.jp/cgi-bin/dict_search.cgi?MT=" & tango & "&sw=0" end tell
アッシも作ってみました。スクリプトやってて、 いちいちスクリプトエディタから用語辞書を開くの めんどくさく感じたことないですか? これは、それを解消するスクリプトです。 ただし、OSA Menuから使ってね。要は現在アクティブなアプリの 用語辞書を開くってやつです。 (ついでにスクリプトエディタも起動してくれます。) --frontmostのアプリケーションの用語辞書を開く tell application "Finder" set the script_editor to application file id "ToyS" set file_path to path to frontmost application ignoring application responses open file_path using script_editor end ignoring end tell --ここまで
tell application "Finder" activate select every item of container window of folder "Cache ト" of folder "omanko" of folder "Netscape Users" of folder "初期設定" of folder "システムフォルダ" of startup disk delete selection select {file "MagicCookie" of folder "omanko" of folder "Netscape Users" of folder "初期設定" of folder "システムフォルダ" of startup disk@` file "Netscape History" of folder "omanko" of folder "Netscape Users" of folder "初期設定" of folder "システムフォルダ" of startup disk} delete selection empty trash end tell
だから、上記のスクリプトは以下のように書いたらどうアルか? ----------------------------------------- tell application "Finder" activate try delete every item of container window of folder "Cache ト" of folder "omanko" of folder "Netscape Users" of folder "初期設定" of folder "システムフォルダ" of startup disk delete {file "MagicCookie" of folder "omanko" of folder "Netscape Users" of folder "初期設定" of folder "システムフォルダ" of startup disk@` file "Netscape History" of folder "omanko" of folder "Netscape Users" of folder "初期設定" of folder "システムフォルダ" of startup disk} end try empty trash end tell --------------------------- ディスクの階層がウチの環境とは違うので、動作テストはしてないアル。 empty trash を消して、動作テストすることをお勧めするアル。
tell application "Finder" activate try delete every item of container window of folder "Cache ト" of folder "omanko" of folder "Netscape Users" of folder "初期設定" of folder "システムフォルダ" of startup disk end try try delete {file "MagicCookie" of folder "omanko" of folder "Netscape Users" of folder "初期設定" of folder "システムフォルダ" of startup disk@` file "Netscape History" of folder "omanko" of folder "Netscape Users" of folder "初期設定" of folder "システムフォルダ" of startup disk} end try empty trash end tell
誰でも使えるように汎用性を持たせてみました。 いかがなもんでしょ。 -- property User : "" on run if User = "" then tell application "Finder" set usernamelist to name of every folder of folder "Netscape Users" of preferences folder end tell set User to item 1 of (choose from list usernamelist with prompt "Userを指定して下さい。") end if tell application "Finder" try delete every item of folder "Cache ト" of folder User of folder "Netscape Users" of preferences folder delete file "MagicCookie" of folder User of folder "Netscape Users" of preferences folder end try end tell end run --
6行でOK。 -- set crt to text returned of (display dialog "クリエータは何にしますか?" default answer "") set fltp to text returned of (display dialog "ファイルタイプは何にしますか?" default answer "") set fld to choose folder with prompt "指定したフォルダ内の、全てのファイルのタイプとクリエータを変換します:" tell application "Finder" set file type of every file of fld to fltp set creator type of every file of fld to crt end tell --