Jump to content

AppleScript sends Publisher text to Powerpoint slide


Recommended Posts

There have endless requests for the addition of scripting capabilities for Affinity, and it is reportedly in the works. But my need couldn't wait, so I decided to see what was possible even without scripting support. Fortunately, AppleScript can do things like type keys (with modifiers) to activate menu items, and maybe even select menu items (I didn't try that).

My business builds cued musical scores in Publisher, then exports the cue text to supertitle slides in PowerPoint. The AppleScript below selects all the text in the frame I've clicked (with type tool), copies it into an AppleScript variable, analyzes it to determine whether it needs to be split into two lines and, if so, finds the space character nearest the middle of the text and adds a return there before creating a new slide in (fully-scriptable) PowerPoint which holds the formatted text. It pauses for a second to let me examine the new slide, then returns me to Publisher.

I've used Mac's Shortcut app to run the script whenever I press F1. Works like a charm!

My script calls on two custom PowerPoint slide styles: "title only" and "blank." If you wanted to make use of this script you would either need to create styles with these names or substitute your style names in the script. 

I'm posting this only because my Affinity mentor, who persuaded me to try switching from (scriptable) InDesign, suggested doing so to see what reactions I might get.

activate application "Affinity Publisher 2"

tell application "System Events"

keystroke "a" using command down --Select all

keystroke "c" using command down --Copy

end tell

delay 0.3

set txt to the clipboard

tell application "Microsoft PowerPoint"

activate

set frontmost to true

delay 0.5

if (class of txt is not text) or (length of txt = 0) then

make new slide at end of active presentation with properties {layout:slide layout blank}

delay 0.3

else

if ("

" is not in txt) and ("

" is not in txt) then --Is there already a lf or cr?

set len to length of txt

if len > 27 then --if more than one line, break at space nearest center

set mid to len / 2 as integer

set off to 0

repeat while id of character (mid + off) of txt ≠ 32

set off to -off

if off ≤ 0 then set off to off - 1

end repeat

set mid to mid + off

set txt to (text 1 thru (mid) of txt) & return & (text (mid + 1) thru len of txt)

end if

end if

set ns to (make new slide at end of active presentation with properties {layout:slide layout title only})

set content of text range of text frame of shape 1 of ns to txt

delay 1.2

end if

end tell

activate application "Affinity Publisher 2"

Link to comment
Share on other sites

2 hours ago, TitlesGuy said:

I'm posting this only because my Affinity mentor, who persuaded me to try switching from (scriptable) InDesign, suggested doing so to see what reactions I might get.

The power of System Events:)
Works even better via Keyboard Maestro.

If the Affinity UI would better follow Apple Human Interface Guidelines, even more would be possible. Sadly, it doesn't. So all we can do is to wait for the native Affinity scripting and hope it will materialize within our remaining lifespan.

MacBookAir 15": MacOS Ventura > Affinity v1, v2, v2 beta // MacBookPro 15" mid-2012: MacOS El Capitan > Affinity v1 / MacOS Catalina > Affinity v1, v2, v2 beta // iPad 8th: iPadOS 16 > Affinity v2

Link to comment
Share on other sites

While I don't know, I expect that Microsoft has a similar set of interface guidelines and the Affinity developers have to choose one set or the other, or aim for some kind of compromise.  I'm not expecting it's practical for designers to create different apps for the two platforms to follow the different HIGs.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.