[Pythonmac-SIG] appscript and quicktime

has hengist.podd at virgin.net
Wed Oct 5 19:36:30 CEST 2005


captnswing wrote:

>the following applescript snippet seems unimplementable in appscript,  to me at least:
>
>=================================================
>if (can export movie 1 as DV stream) is true then
>    try
>        with timeout of 360 seconds
>            export movie 1 to POSIX file the_newname as DV stream  using settings the_settings with replacing
>        end timeout
>    on error errorMsg number errNo
>        ...
>    end try
>end if
>=================================================


#!/usr/bin/env pythonw

from appscript import *
from macfile import File

qtp = app('QuickTime Player')

m = qtp.movies[1]
if m.can_export(as=k.DV_stream):
    try:
        m.export(to=File(the_newname), as=k.DV_stream,
                using_settings=the_settings, replacing=True, timeout=360)
	except Exception, e:
		...


>=================================================
>--get number of tracks and kind of movie
>tell application "QuickTime Player"
>    activate
>    open the_file
>    tell movie file_name
>        set track_count to the count of tracks
>        set track_kind to the kind of track 1
>    end tell
>end tell
>
>--if movie is muxed mpeg
>if (track_count is equal to 1) and (track_kind contains "Muxed") then
>.....
>=================================================

qtp.activate()
qtp.open(the_file)
m = qtp.movies[file_name]
track_count = m.tracks.count()
track_kind = m.tracks[1].kind.get()

if track_count == 1 and 'Muxed' in track_kind:
    ...


>it is unclear to me how to get to the track_kind property of a movie
>are not all properties and functions mapped over to appscript?

Everything maps (barring bugs). As Nick says, use appscript's help system for viewing applications' dictionaries; it's pretty extensive (roughly on par with Script Debugger's dictionary tools, though CLI-based rather than GUI).


>also I wonder how you can tell which appscript command takes what  parameters.

See the appscript documentation for info on appscript-defined parameters (e.g. 'timeout'), and use the help system to view the command's basic definition. The rest is searching secondary resources (supplementary documentation, sample scripts, mailing list discussions, etc.), educated guesswork and trial and error, same as usual. Application dictionaries have always been frustratingly vague on the finer details; appscript only saves you from the AppleScript language, not the shortcomings of individual applications.


>and finally, what does the k. in the documentation

'Keyword'. It's a fake namespace, part of appscript's syntactic sugar, used to specify types and enumerations.


>  (and the above get () call) stand for?

Unlike AppleScript, which can perform 'implicit gets' when evaluating a literal application reference, appscript only sends a get event when you tell it to. Again, this is in the appscript documentation.

HTH

has
-- 
http://freespace.virgin.net/hamish.sanderson/


More information about the Pythonmac-SIG mailing list