0
votes

We've got an applescript that tells keynotes to delete slides based on criteria. The new keynote does not have an applescript dictionary, but leaves the old keynote in a subdirectory. So I'm trying to tell AppleScript to talk with the older app rather than the new one.

If I just

tell application "Clean Install:Applications:iWork '09:Keynote.app"

It works, but it doesn't recognize any of the keynote dictionary terms. (delete a slide). So I need to pull out my old friend "using terms from". The challenge here is that this is a precompile directive, so you have to use a string literal, which I don't have on the end user's machine due to different hard drive names.

Ok, still have a plan here. I will write out a new applescript file with the 'using terms from application "Clean Install:Applications:iWork '09:Keynote.app"' and then execute that file... Genius... except for the fact that when AppleScript compiles this line:

using terms from application "Clean Install:Applications:iWork '09:Keynote.app"

Gets changed to:

using terms from application "Keynote"

Which of course calls the new keynote's dictionary which is empty.

Any thoughts on how to keep applescript from helping me out in this way? (or is there a better plan?)

full code:

using terms from application "Clean Install:Applications:iWork '09:Keynote.app"

    --using terms from application "Clean Install:Applications:iWork '09:Keynote.app"
    tell application "Clean Install:Applications:iWork '09:Keynote.app"

        activate

    end tell
end using terms from

many thanks!

2

2 Answers

0
votes

I'm flyin' blind here (don't have keynote) ... but have you tried using a pre-defined app string as a variable and raw event codes?

You can use Smile to easily get raw event codes by

  • making a new script window in Smile;
  • using the "tell" menu item from the Action menu to make that script window application-specific (no tell block needed);
  • write a line of code; select line of code
  • then use the "Copy translate" menu item (cmd-shift-C) to copy the raw event codes
  • pasting that raw event code code into a different window that has your working (normal tell block) script

This is what it looks like when I do this for the Mail app:

set origMail to "MyDrive:Applications:Mail.app"

tell application origMail
    delete («class mssg» 1 of «class mbxp» "INBOX" of «class mact» 1)
end tell

( When put in a normal tell block, that line of code would be "delete (message 1 of mailbox "INBOX" of account 1)" )

0
votes

I haven't tried this but I think it will work... when you compile your code with "using terms from" just place your new version of Keynote in the trash. That should force it to use the old version of Keynote's dictionary and your code should compile. If you then save that code as an "applescript application" then it should work on anybody's computer without need to recompile. NOTE: you may need to restart your computer before this trick would work.

Then you just have the problem of targeting the right application on the user's computer because they too might have both versions. Here's some code to find the path to older versions of Keynote and how you would target that.

set lsregister to "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister"
set appName to "Keynote.app"
set nonapplescriptVersion to "6.0"

-- get the path to all Keynote apps
set appPaths to paragraphs of (do shell script lsregister & " -dump | grep " & quoted form of appName)

-- find the one with a version number less than the nonapplescriptVersion of Keynote
set appPath to missing value
repeat with anApp in appPaths
    try
        -- extract the path
        set AppleScript's text item delimiters to "/"
        set tis to text items of anApp
        set thisPath to "/" & (items 2 thru end of tis) as text
        set AppleScript's text item delimiters to ""

        -- check the version
        if (version of application thisPath) is less than nonapplescriptVersion then
            set appPath to thisPath
            exit repeat
        end if
    end try
end repeat
if appPath is missing value then error "Needed application version not installed."

-- use the older version
using terms from application "Keynote"
    tell application appPath
        activate
        -- do whatever
    end tell
end using terms from