Re: Running ruby (utilizing appscript) from do shell script
Re: Running ruby (utilizing appscript) from do shell script
- Subject: Re: Running ruby (utilizing appscript) from do shell script
- From: "Mark J. Reed" <email@hidden>
- Date: Wed, 4 Jun 2008 10:33:56 -0400
First question: why? The idea behind appscript is to let you use
something besides AppleScript to do app scripting; if you're going to
use AppleScript anyway, I'm not sure what calling out to
ruby/appscript buys you.
But I suspect you're running into newline issues. A multiline AS
string has carriage returns between the lines; Ruby (and UNIX-level
tools generally) expects linefeeds. Try sticking this in front of the
do shell call:
set text item delimiters to return
set commandLines to text items of theCommand
set text item delimiters to linefeed -- use "ASCII character 10" pre-Leopard
set theCommand to commandLines as text
On Wed, Jun 4, 2008 at 10:14 AM, James Nierodzik
<email@hidden> wrote:
> Hello scripters,
> After reading the recent posts on rb-appscript I decided to give it a whirl.
> So I started by just redoing a recent script than came across here and
> after a little tinkering I got it to work. From there I wanted to try and
> get the ruby code to run from inside an applescript and this is what I have
> come up with.
>
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> set rb to "require 'rubygems'
> require 'appscript'
> include Appscript
> require 'osax'
> include OSAX
> # Set Duration Params
> new_duration = 10
> # App Declarations
> Finder = app('Finder')
> QT = app('QuickTime Player.app')
> theFile = osax.choose_file()
> theMovie = Finder.files[theFile].name.get
> savePath = osax.choose_folder()
>
>
>
> QT.open(theFile)
> QT.select_all(theMovie)
> QT.documents[theMovie].selection_end.set(new_duration *
> (QT.documents[theMovie].time_scale.get))
> QT.documents[theMovie].trim
> QT.documents[theMovie].save_self_contained(:in => (String(savePath) + '/' +
> theMovie))
> QT.documents[theMovie].close"
> set theCommand to "ruby -e \"" & rb & "\""
> do shell script theCommand
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Here's where I get lost though. If I copy the contents of theCommand
> and paste it into a terminal window the script runs fine. However when it's
> ran via the do shell script theCommand I get back this error
>
>
> -e:1: syntax error, unexpected tIDENTIFIER, expecting $end
> require 'rubygems'
> require 'appscript'
> include Appscript
> require 'osax'
> include OSAX
> # Set Duration Params
> new_duration = 10
> # App Declarations
> Finder = app('Finder')
> QT = app('QuickTime Player.app')
> theFile = osax.choose_file()
> theMovie = Finder.files[theFile].name.get
> savePath = osax.choose_folder()
>
> QT.open(theFile)
> QT.select_all(theMovie)
> QT.documents[theMovie].selection_end.set(new_duration *
> (QT.documents[theMovie].time_scale.get))
> QT.documents[theMovie].trim
> QT.documents[theMovie].save_self_contained(:in => (String(savePath) + '/' +
> theMovie))
> QT.documents[theMovie].close
> ^
>
> Any ideas what's going on?
> Thanks!
>
> James Nierodzik
> P Please consider the environment
> before printing this email.
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
>
--
Mark J. Reed <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden