Re: Scripting PowerPoint
Re: Scripting PowerPoint
- Subject: Re: Scripting PowerPoint
- From: Paul Berkowitz <email@hidden>
- Date: Mon, 06 Feb 2006 09:26:57 -0800
- Thread-topic: Scripting PowerPoint
Title: Re: Scripting PowerPoint
On 2/5/06 11:03 AM, "Rick Davis" <email@hidden> wrote:
> Thanks Paul,
>
> I changed it to:
>
> tell application "Microsoft PowerPoint"
> do Visual Basic "ActivePresentation.Export Path:=\"Macintosh
> HD:Users:rickdavis:Desktop:presentation_name\", FilterName:=\"tif\""
> end tell
>
> Works like a charm. A follow up question. Is there any way to set
> the path according to the name of the active presentation? I'm hoping
> to add the script as a folder action, then drop a collection of
> presentations into the folder to create a series of slides in a new
> folder for each presentation that corresponds to the presentation
> name. Then after a delay delete the original presentation from the
> folder. I've not worked with VBA much but will head towards the VB
> Help now.
>
You're just asking if you can get the name or the path of the active presentation in AppleScript? Of course you can - just check the PowerPoint AppleScript dictionary. 'presentation' has no less than three such properties: 'name' (includes the extension, if any), 'full name' (that's really the full path to the file, including the extension), and 'path' (which is actually the path to the file's folder). Or are you saying you want to rename the exported graphics to the same as the names of the individual slides in the presentation? Well, slides don't have names. You could get the text of the first shape that's a text box - if you know for sure that every slide has a text box, that if there's more than on text box which one would gave the text you want, and that the text is never too long, etc. etc. So you'd better say what you want. Then you could change the the name of the "Slide1" file using Finder scripting.
In no case do you need to know VBA. I only mentioned VBA because of the missing "Export" command from AppleScript. Otherwise just about everything in VBA has been translated into AppleScript. (I wouldn't be surprised if there are a couple other missing commands, mind you.) The VBA Help can be useful, but it makes more sense to check the PowerPoint AppleScript Reference, which you can find at http://www.microsoft.com/mac/ , then follow the links to Resources/Developer/AppleScript. The VBA Help has been "translated" into AppleScript here, plus you get everything in the correct terms, with a few other helpful AppleScript-oriented instructions.
Anyway, if all you're asking is "how do you get the name of the presentation into the 'do Visual Basic' "Export" command, I think you probably need to learn the basics of AppleScript before you go on. There are a lot of good books around. Personally, I think the best is Matt Neuburg's "AppleScript: The Definitive Guide" 2nd edition (O'Reilly), but others are Hanaan Rosenthal's "AppleScript: A Comprehensive Guide..." (it's really comprehensive) and Danny Goodman's "AppleScript Handbook". The O'Reilly "AppleScript Missing Manual" is an easy simple introduction but not exhaustive.
What you want here is to make a folder named after the presentation but without the extension, right? You could fiddle around trying to parse the name looking for extensions, but it's better to use Finder scripting or the 'info for' scripting addition to make sure. Since we know that 'full name' gets us the file's full path, putting 'alias' in front of that gets us the actual file, and 'info for' can get us the name and any extension. If there is an extension, 'text 1 thru -((count nameExtension) + 2) of presName' leaves out the period and the extension. When putting together the path for the subfolder for the "Export" method, you need to insert a ":" at the end of the folderPath, since PowerPoint's 'path' property omits the final colon. (Putting a final colon at the very end of the new subfolder name is optional: it works with or without.) There are other ways to get the same thing, but this is quickest. And, frankly, if this started out as a folder action, then you'd already have the alias without needing to find it from PowerPoint.
So what you want is this:
tell application "Microsoft PowerPoint"
set {presName, presFullPath, folderPath} to active presentation's {name, full name, path}
set nameExtension to name extension of (info for alias presFullPath)
if nameExtension ≠ "" then
set plainName to text 1 thru -((count nameExtension) + 2) of presName
else
set plainName to presName
end if
do Visual Basic "ActivePresentation.Export Path:=\"" & folderPath & ":" & plainName & "\", FilterName:=\"tif\""
close active presentation saving no
end tell
tell application "Finder"
delete file presFullPath
end tell
--
Paul Berkowitz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden