Keynote properties not being passed to Applescript - applescript

I need my Mac to say the number of the current slide when presenting. I've written the below script, but it's not working as expected.
on slideNumber()
tell application "Keynote"
return the slide number of the current slide of the front document
end tell
end slideNumber
repeat
say slideNumber()
delay 1
end repeat
When I run this is will correctly say the current slide number in Keynote, however if I go to Keynote and change slides, or start presenting the slides, the Applescript doesn't update the slide number. If I go back to the Applescript window it immediately starts saying the correct slide number.
I've also tried this using:
on idle
say slideNumber()
return 1
end idle
and exporting as a stay-open application, but the same problem occurs.
Is it not possible to have the Applescript application return the correct slide number without the application/script being in the foreground? I'm using Keynote 6.2 if that's relevant.

I realize this question is old. For what it's worth, having seen it just now, your script works perfectly fine for me. I'm on macOS Sierra (10.12.1) using Keynote version 7.0.5. Copy/pasted your script into Script Editor and ran it. Speaks correct slide number as I switch between slides both in edit mode and while presenting.
Could there have been something wrong with the scripting interface of Keynote 6.2? I have seen cases where a buggy app just doesn't do what it advertises, and a later version fixes it. Do you still specifically need this to run against Keynote 6.2?

Related

How to minimize MOG using applescript

I am working on an AppleScript to toggle between minimize and maximize of specific windows. I have it working pretty well. But I am running into a specific issue with one application the MOG app for Mac does not seem to have a variable for miniaturize, collapse, or minimize.
I know that I could use click to toggle the window, but I would prefer a solution that works with the API.
Here is the applescript just for MOG:
tell application "MOG"
set (miniaturized of windows whose miniaturizable is true) to true
end tell
I would really appreciate it if someone could point me in the right direction.
Not every application is going to allow something like miniaturization of windows via AppleScript, even when the application is scriptable. One way to find out the properties of an application's window:
tell application "MOG"
get properties of window 1
end tell
You can also open the MOG dictionary and find out what you're able to script. Pressing cmd-shift-o will open a window listing all applications' scripting dictionaries.

Positioning windows with applescript on dual monitors

I have 2 air applications that I wrote. They auto fullscreen after 10 seconds. Before then, they need to be sent to their proper displays. "app_1" needs to run on display 1, "app_2" needs to run on display 2.
Essentially, I have this code:
do shell script "cd /Applications/app_1.app/Contents/MacOS/ ; open app_1;"
which works for me flawlessly. Both apps are launched that way, and there is some code for ensuring that the apps weren't already open, and closing them if they were.
I tried to add in a script to position the app after it is launched:
do shell script "cd /Applications/app_1.app/Contents/MacOS/ ; open app_1;"
tell first window of application "app_1" to set bounds to {0,0,1920,1080}
This gives me an error:
app_1 got an error: Can't set bounds of window 1 to {0,0,1920,1080}
I tried adding a delay of a couple seconds before the set bounds, in case the application hadn't yet launched when the set bounds fired off, however this didn't change anything.
I also tried setting the bounds to something like {100,100,200,200} just to see if I had the screen coordinates wrong or something, but still the exact same error, only with the {100,100,200,200} instead of the original 1920x1080 coordinates.
Anyone have any insight on this? I've been trying to find the solution on google for a couple of hours now.
It sounds like your app isn't exposing the standard "window" class. I don't know if AIR apps are supposed to automatically take care of this and it's not working—if so, you'll want to debug that.
But another alternative is to use UI Scripting to control its windows externally. Instead of this:
tell first window of application "app_1" to set bounds to {0,0,1920,1080}
Do this:
tell application "System Events"
set position of first window of application process "app_1" to {0, 0}
set size of first window of application process "app_1" to {1920,1080}
end tell
However, this will only work if you've gone to the Universal Access pane of System Preferences and checked "Enable access for assistive devices" (or done the same via API, "sudo touch /var/db/.AccessibilityAPIEnabled", etc.).

move any window outside screen under Mac OS

I am trying to hide (or to move outside teh screen bounds) any window (I mean not belonging to my application).
I tried using Accessibility but unfortunately, there is always a small part of the window which is still on the screen.
Here are my questions:
- Is there a way to completly move a window outside the screen using accessibility?
- Is there an alternative way (Apple Script, ...) to achive that?
Thanks!
I am also using Lion and I am quite sure it was working before.
I am discovering a lot of small things like that in 10.7.
Apple have introduced more changes that it seem.
Thanks for your trial.
I tried the following code with a TextEdit window. It wouldn't work. I tried to move it off all 4 sides of the screen and none of it worked (as you explained there's always a part of the window showing). I'm using 10.7. I'm pretty sure I could do it in 10.6 and earlier... maybe it's a 10.7 thing???
tell application "System Events"
tell process "TextEdit"
set theWindows to windows
repeat with aWindow in theWindows
tell aWindow
set currentPosition to position
set position to {-1000, item 2 of currentPosition}
end tell
end repeat
end tell
end tell

Xcode 4 - Create shortcut for tabs

Is there a way to assign shortcut to applescript that can control tabs on Xcode 4 ? Something like this works for Safari, but not Xcode 4 :
try
tell front window of application "Xcode" to set current tab to tab 1
on error
tell front window of application "Xcode" to set current tab to last tab
end try
(I have an error : A property can’t go after this identifier.)
I know I can switch tabs with cmd-}, I want to be able to go to a tab by its number
Because Xcode 4 is so young, the Applescript dictionary is basically empty. You may have to wait for Xcode 4.1 or 4.2 before you can do any kind of complicated scripting.
I would file a radar bug if this is really important to you. It's like voting. If you are lucky enough to have a WWDC ticket, make sure to mention it to all the apple engineers you meet there.
Xcode 4 was an ambitious redesign. In an effort to ship, quite a few features got cut (applescript, user scripts being the more glaring). I would expect them to make a comeback over time, but you need to make your needs known.

How can I use AppleScript to check if PowerPoint is playing a presentation?

I'm trying to write some AppleScript that checks if PowerPoint 2011 is currently playing a presentation.
Previously, I wrote the following code for Keynote.
on isKeynotePlaying()
tell application "Keynote"
get properties
return (not frozen) and playing
end tell
end isKeynotePlaying
After searching through PowerPoint's AppleScript library, properties and attributes of classes, and Google search results, I still haven't been able to generate an equivalent solution. Any ideas?
After delving even deeper into PowerPoint's AppleScript library, I stumbled upon the slide show view class. Here's my solution.
on isPowerPointPlaying()
tell application "Microsoft PowerPoint"
return slide state of slide show view of slide show window of active presentation is slide show state running
end tell
end isPowerPointPlaying

Resources