# Quicktime and Ruby

**URL:** <https://www.ruby-forum.com/t/quicktime-and-ruby/108964>\
**Category:** Ruby\
**Created:** [July 10, 2007, 3:40am UTC](https://www.ruby-forum.com/t/quicktime-and-ruby/108964 "2007-07-10T03:40:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [July 10, 2007, 3:40am UTC](https://www.ruby-forum.com/t/quicktime-and-ruby/108964/1 "2007-07-10T03:40:17Z")

</div>

Hey all

I read a previous post from early April about working applescript  
into Ruby. BUT…

I need to be able to convert mp3s into hinted movie format (which  
isn’t covered ANYWHERE). Whats the best way to do this in any  
applescript wrapper?

Thanks,  
Ari  
-------------------------------------------|  
Nietzsche is my copilot

---

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [July 10, 2007, 5:33am UTC](https://www.ruby-forum.com/t/quicktime-and-ruby/108964/2 "2007-07-10T05:33:04Z")

</div>

Ari B. wrote:

> Hey all
> 
> I read a previous post from early April about working applescript  
> into Ruby. BUT…
> 
> I need to be able to convert mp3s into hinted movie format (which  
> isn’t covered ANYWHERE). Whats the best way to do this in any  
> applescript wrapper?
> 
> Thanks,  
> Ari  
> -------------------------------------------|  
> I’m not sure I understand the question. But does this help

[rb-appscript.rubyforge.org](http://rb-appscript.rubyforge.org)

This isn’t what you’re looking for, but gives an example of working with  
a movie. I got the following in response to a question I asked from HAS:

require ‘appscript’  
include Appscript  
QTP = app(‘QuickTime Player.app’)

# To export the middle frame of a movie file to a PICT file:

movie = QTP.open(MacTypes::Alias.path(‘/path/to/your movie.mov’))[0]  
movie.current\_time.set(movie.duration.get / 2)  
movie.export(:to=\>MacTypes::FileURL.path(‘/path/to/middle  
frame.pict’), :as=\>:picture)  
movie.close

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [July 10, 2007, 10:42am UTC](https://www.ruby-forum.com/t/quicktime-and-ruby/108964/3 "2007-07-10T10:42:28Z")

</div>

12 34 wrote:

> This isn’t what you’re looking for, but gives an example of working with  
> a movie.

[…]  
You’re very close. Just needs some minor changes:

#!/usr/local/bin/ruby

require ‘appscript’  
include Appscript

QTP = app(‘QuickTime Player.app’)

infile = ‘/path/to/your file.mp3’  
outfile = ‘/path/to/your file.mov’

movie = QTP.open(MacTypes::Alias.path(infile))[0]  
movie.export(:to=\>MacTypes::FileURL.path(outfile), :as=\>:hinted\_movie)  
movie.close

HTH

## has

[http://appscript.sourceforge.net](http://appscript.sourceforge.net)  
[http://rb-appscript.rubyforge.org](http://rb-appscript.rubyforge.org)

---

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [July 10, 2007, 2:13pm UTC](https://www.ruby-forum.com/t/quicktime-and-ruby/108964/4 "2007-07-10T14:13:26Z")

</div>

THANK YOU SO MUCH!

I’m SO glad that all I needed to do was alter the ‘:as’ statement.  
You have made my life so much easier.

You see, there are 9000 songs which I am getting paid to convert.

has rules,  
aRi  
-------------------------------------------------------|  
~ Ari  
crap my sig won’t fit

---

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [July 10, 2007, 2:06pm UTC](https://www.ruby-forum.com/t/quicktime-and-ruby/108964/5 "2007-07-10T14:06:25Z")

</div>

On Jul 9, 2007, at 11:33 PM, 12 34 wrote:

> require ‘appscript’  
> include Appscript  
> QTP = app(‘QuickTime Player.app’)
> 
> # To export the middle frame of a movie file to a PICT file:
> 
> movie = QTP.open(MacTypes::Alias.path(’/path/to/your movie.mov’))[0]  
> movie.current\_time.set(movie.duration.get / 2)  
> movie.export(:to=\>MacTypes::FileURL.path(’/path/to/middle  
> frame.pict’), :as=\>:picture)  
> movie.close

I saw that, and in fact that’s what I’m using as my library. But I  
need to convert the file into Hinted Movie format. In quicktime, it’s  
under File -\> Export -\> Hinted Movie

What would I write in ‘:as’ if I wanted to do that? Or where could I  
get a list of possible file conversions for this?

aRi  
--------------------------------------------|  
If you’re not living on the edge,  
then you’re just wasting space.

---

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [July 10, 2007, 2:24pm UTC](https://www.ruby-forum.com/t/quicktime-and-ruby/108964/6 "2007-07-10T14:24:28Z")

</div>

Hey, thanks for your help. I just have a quick question.

On Jul 10, 2007, at 4:42 AM, hengist podd wrote:

> #!/usr/local/bin/ruby
> 
> require ‘appscript’  
> include Appscript
> 
> QTP = app(‘QuickTime Player.app’)
> 
> infile = ‘/path/to/your file.mp3’  
> outfile = ‘/path/to/your file.mov’

What does the ‘MacTypes::Alias.path(infile))[0]’ do?

> movie = QTP.open(MacTypes::Alias.path(infile))[0]  
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
> I don’t understand what the Alias and the [0] are doing. I guess it  
> makes an alias of the file?

> movie.export(:to=\>MacTypes::FileURL.path(outfile), :as=\>:hinted\_movie)  
> movie.close

-------------------------------------------|  
Nietzsche is my copilot

---

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [July 10, 2007, 4:23pm UTC](https://www.ruby-forum.com/t/quicktime-and-ruby/108964/7 "2007-07-10T16:23:23Z")

</div>

Ari B. wrote:

> Hey, thanks for your help. I just have a quick question.

> What does the ‘MacTypes::Alias.path(infile))[0]’ do?
> 
> > movie = QTP.open(MacTypes::Alias.path(infile))[0]  
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
> > I don’t understand what the Alias

MacTypes::Alias.path(…) creates a new Alias object. The MacTypes  
module is discussed in more detail in the appscript documentation.

> and the [0] are doing.

QTP’s ‘open’ command returns an array of references to the newly opened  
movies, in this case [app(‘QuickTime Player’).movies[‘some file’]].  
However, we just want the first item in that array so we call its #[]  
method.

HTH

has

p.s. The equivalent line in AppleScript would read:

```
set theMovie to item 1 of (open alias "HD:path:to:your file.mp3")

```

except that AppleScript uses an HFS path string rather than a POSIX one  
for legacy reasons.

–  
[http://appscript.sourceforge.net](http://appscript.sourceforge.net)  
[http://rb-appscript.rubyforge.org](http://rb-appscript.rubyforge.org)

---

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [July 11, 2007, 3:41pm UTC](https://www.ruby-forum.com/t/quicktime-and-ruby/108964/8 "2007-07-11T15:41:50Z")

</div>

Ari B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hey all
> 
> I read a previous post from early April about working applescript  
> into Ruby. BUT…
> 
> I need to be able to convert mp3s into hinted movie format (which  
> isn’t covered ANYWHERE). Whats the best way to do this in any  
> applescript wrapper?

You can tell QuickTime Player to open each file and export it as a  
hinted movie. This is not really a Ruby matter, though certainly you  
might use Ruby as a basis for sending the necessary Apple events. m.

---

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [July 11, 2007, 3:54pm UTC](https://www.ruby-forum.com/t/quicktime-and-ruby/108964/9 "2007-07-11T15:54:54Z")

</div>

Ari B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > frame.pict’), :as=\>:picture)  
> > movie.close
> 
> I saw that, and in fact that’s what I’m using as my library. But I  
> need to convert the file into Hinted Movie format. In quicktime, it’s  
> under File → Export → Hinted Movie
> 
> What would I write in ‘:as’ if I wanted to do that? Or where could I  
> get a list of possible file conversions for this?

As I said, this is not a Ruby matter. You have to read the dictionary  
(the AppleScript dictionary). m.
