Skip to content

Instantly share code, notes, and snippets.

@scateu
Last active October 24, 2024 02:32
Show Gist options
  • Save scateu/0c196b5a86c0f5c31f28fc150a29056d to your computer and use it in GitHub Desktop.
Save scateu/0c196b5a86c0f5c31f28fc150a29056d to your computer and use it in GitHub Desktop.
pbpaste2keynote
-- credit: ChatGPT.
-- This script fetch text from pasteboard and append to the end of opened Keynote.
-- If multiple Keynote opened, the most front will be selected.
-- Usage: Open it in Script Editor.app, export it as an Applcation. Then drag it into Dock.
-- KNOWN BUG: "shortcuts not allowed to sent keystroke, system events blahblah', just kill "System Events" from Activity Monitor.
-- tell application "System Events" to keystroke "c" using command down
tell application "System Events"
if not (exists (processes where name is "Keynote")) then
display dialog "Keynote is not running." buttons {"OK"} default button "OK"
return
end if
end tell
-- set clipboardInfo to clipboard info
-- set theClipboard to the clipboard as record
-- if clipboardInfo contains {"«class utf8»", "string"} then
-- set myText to make new text item at end of text items with properties {object text:theClipboard}
-- set the position of myText to {100, 100} -- Adjust position as needed
-- else if clipboardInfo contains "TIFF" then
-- -- set myImage to make new image with properties {file type:clipboard}
-- tell application "System Events" to keystroke "v" using command down
-- end if
tell application "Keynote"
activate
if (count of documents) = 0 then
display dialog "No Keynote documents are open." buttons {"OK"} default button "OK"
return
end if
tell document 1
set newSlide to make new slide with properties {base layout:slide layout "Blank"} at end of slides
tell newSlide
tell application "System Events" to keystroke "v" using command down
end tell
end tell
end tell
tell application "System Events" to keystroke (ASCII character 9) using command down -- Cmd-Tab
@scateu
Copy link
Author

scateu commented Oct 23, 2024

property thisThemeName : "Black"

tell application "Keynote"
	activate
	try
		-- GET THE THEME NAMES
		set the themeNames to the name of every theme
		
		-- CHECK FOR THEME
		if thisThemeName is not in the themeNames then
			error "The theme “" & thisThemeName & "” is not installed on this computer."
		end if
		
		-- MAKE NEW PRESENTATION
		set thisDocument to ¬
			make new document with properties ¬
				{document theme:theme thisThemeName, width:1920, height:1080}
		
		tell thisDocument
			-- FORMAT THE FIRST SLIDE
			set the base layout of the first slide to slide layout "Title"
			tell the first slide
				set the object text of the default title item to "My Presentation"
				set the object text of the default body item to "Fun Stuff for You to Know"
			end tell
			
			-- ADD INFORMATION SLIDE
			set thisSlide to make new slide with properties ¬
				{base layout:slide layout "Title & Bullets"}
			tell thisSlide
				set the object text of the default title item to "Main Point"
				set the object text of the default body item to ¬
					"Bullet Point 1" & return & "Bullet Point 2" & return & "Bullet Point 3"
			end tell
			
			-- ADD CLOSING SLIDE
			set thisSlide to make new slide with properties ¬
				{base layout:slide layout "Title - Center"}
			tell thisSlide
				set the object text of the default title item to "Thank You!"
			end tell
			
		end tell
		
		-- PLAY THE PRESENTATION
		start thisDocument from the first slide of thisDocument
		
	on error errorMessage number errorNumber
		if errorNumber is not -128 then
			display alert ("ERROR " & errorNumber) message errorMessage
		end if
	end try
end tell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment