7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AppleScript+RubyでWeb検索ダイアログ

Last updated at Posted at 2014-05-19

初Mac(MacBook Air 11" 2014)を購入したので練習がてらに。

AppleScriptの文法が慣れない&ライブラリを把握していないので、AppleScriptに加えて私が慣れているRubyも併用しました。

display dialog "Input Search Keyword..." default answer ""
set kw to text returned of result

"require 'cgi'
uri_list = {
	'g' => 'http://google.com/search?q=', 
	'i' => 'http://google.com/search?btnI&q=',
	'wi' => 'http://ja.wikipedia.org/?search=',
	'wa' => 'http://www.wolframalpha.com/input?i='
}
res = if (uri = uri_list[ARGV.first])
	uri + CGI.escape(ARGV[1..-1].join(' '))
else
	uri_list.first[1] + CGI.escape(ARGV.join(' '))
end
puts res
"
set rb to quoted form of result

set res to do shell script "/usr/bin/ruby -e " & rb & " " & kw
open location res

実行するとダイアログが出てくるので、
MacBook Airで"MacBook Air"をGoogle検索したり、
i qiitaで"qiita"をI'm Feeling Lucky検索したり、
wi applescriptで"applescript"をWikipedia検索します。

KeyRemap4MacBookとかでショートカットから実行できるようにしておくと便利かもしれない。

参考にさせて頂いたサイト


ほとんどRubyじゃね?

はい

QuickSilverとかAlfredでよくね?

はい

7
6
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?