Created
November 28, 2011 01:27
-
-
Save nbqx/1398698 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%w(sinatra notify).each{|x| require x} | |
require "sinatra/reloader" if development? | |
configure do | |
TITLE = "InDesign Scripting Server" | |
INDESIGN_VERSION = "CS5" | |
end | |
get "/" do | |
Notify.notify TITLE, "Target Versiion InDesign #{INDESIGN_VERSION}" | |
content_type :text | |
"ok" | |
end | |
## curl -X POST -F 'script=alert("ok")' http://localhost:4567 | |
post "/" do | |
##Notify.notify TITLE, "Execute Script" | |
scrt = params[:script] | |
create_javascript(scrt) | |
exec | |
content_type :text | |
"ok" | |
end | |
def exec | |
if File.exists? File.dirname(__FILE__)+"/tmp.log" | |
File.unlink File.dirname(__FILE__)+"/tmp.log" | |
end | |
create_dispatcher_applescript | |
`osascript #{File.dirname(__FILE__)+"/tmp.scpt"}` | |
end | |
def create_javascript(scrt) | |
open(File.dirname(__FILE__)+"/tmp.jsx","w"){|f| f.print scrt} | |
end | |
def create_dispatcher_applescript | |
override_js = <<JS | |
var file=new File('#{File.expand_path(File.dirname(__FILE__))+'/tmp.log'}'); | |
file.encodign='UTF-8';file.lineFeed='Mac';file.open('w'); | |
$.write=function(){file.seek(0,2);file.write(arguments[0])}; | |
$.writeln=function(){file.seek(0,2);file.writeln(arguments[0])}; | |
JS | |
scrt = <<SCRT | |
tell application \"Adobe InDesign #{INDESIGN_VERSION}\" | |
activate | |
do script \"#{override_js} $.evalFile('#{File.expand_path(File.dirname(__FILE__))+'/tmp.jsx'}')\" language javascript | |
end tell | |
SCRT | |
open(File.dirname(__FILE__)+"/tmp.scpt","w"){|f| f.print scrt} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment