Skip to content

Instantly share code, notes, and snippets.

@hyuki0000
Created October 4, 2017 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hyuki0000/de7691fa26c7cca9ebd9b8303e016530 to your computer and use it in GitHub Desktop.
Save hyuki0000/de7691fa26c7cca9ebd9b8303e016530 to your computer and use it in GitHub Desktop.
URLをオープンするだけのアプリを作るスクリプト
#!/usr/bin/env ruby
# cf. http://bit.ly/2raKfLZ
# makeopenapp - URLをオープンするだけのスクリプトをMacのアプリケーションにする
if ARGV.length != 2
abort("Usage: makeopenapp URL Example.app")
end
url = ARGV[0]
appname = ARGV[1]
scriptname = 'open.rb'
open(scriptname, "w") do |f|
f.puts <<-"EOD"
#!/usr/bin/env ruby
url = '#{url}'
system("open -a Safari #{url}")
EOD
end
system("mkdir -p #{appname}/Contents/MacOS")
system("mkdir -p #{appname}/Contents/Resources")
open("#{appname}/Contents/Info.plist", "w") do |f|
f.puts <<-"EOD"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>#{scriptname}</string>
</dict>
</plist>
EOD
end
system("cp #{scriptname} #{appname}/Contents/MacOS/")
system("chmod +x #{appname}/Contents/MacOS/#{scriptname}")
system("rm #{scriptname}")
puts "#{appname} is created."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment