Remote AppleScript Events - applescript

I'm trying to open a QuickTime video on a remote computer but running into some issue.
Can someone help?
This is the code I've got so far, it's able to open the video but don't know how to get it to play...
set TheView2 to "eppc://username:password#TheView2.local"
set remoteFinder to application "Finder" of machine TheView2
using terms from application "Finder"
tell remoteFinder
open application file id "com.apple.QuickTimePlayer"
try
using terms from application "QuickTime Player"
tell application "QuickTime Player" of machine TheView2
open "Macintosh HD:Users:mini:Desktop:cache.mov"
end tell
end using terms from
on error errText number errNum
display dialog "Some other error: " & errNum & return & errText
end try
end tell
end using terms from

After you open the movie using the remote version of Quicktime just issue the "play" command in the same block of code. By the way, it is a bad idea to have nested tell blocks. Specifically in your case you have the Quicktime tell block inside the Finder tell block. Basically you're telling the Finder to tell Quicktime to do something. Why? The Finder doesn't need to issue any commands to Quicktime because applescript can do that itself. So separate the 2 tell blocks from each other. You'll have less conflicts that way.

Related

AppleScript plays playlist in Music.app on macOS Monterey

I'm working on this Alfred Workflow: https://github.com/gustavosaez/Alfred-Workflow-Apple-Music-Playlist
And today I'm looking for a day to "automate" the play music in background or hidden (to avoid open the application and click PLAY).
I found a way to set the mouse click on a screen position (specific on the play button), but it works only if the app is visible and if the resolution of screen is the same of mine.
I search about UI Elements for Music.app and didn't find anything.
The problem is:
When Alfred opens the chosen link, Music.app take a few seconds to open and load the playlist selected;
After this, space/play command is inactive, so I think to create a script that gets the current page and play the playlist in shuffle mode.
Any idea?
some ideas:
tell application "Music"
-- tell application "System Events" to tell process "Music" to click at {620, 374}
play current playlist
end tell
|
tell application "Music"
-- tell application "System Events" to tell process "Music" to click at {620, 374}
play {workflowPlaylistName}
end tell
tell application "System Events"
keystroke "h" using command down
end tell
I'm confused why you are trying to use mouse clicks or keystrokes, instead of just using
tell application "Music"
play
end tell
or
tell application "Music"
play the playlist named "{query}"
end tell
and pass the name of the playlist as query

AppleScript works in Script Editor but not as application

I am pretty new to programming, especially with AppleScript. I wrote a simple script for Valentine's Day to play a song from iTunes and then open a flash animation file in Safari. When I run the script in ScriptEditor, everything works as desired, but when I export as a standalone application, it fails at the command to enable full-screen mode. I am assuming it is an issue with System Events. To be clear, the application functions to the end, but at the keystroke command I hear an alert sound and the window remains as-is.
I am running Yosemite, and am fully updated.
Ideally, I would like to open the file in Google Chrome to utilize Presentation Mode, but I can't even get Chrome to open the file.
Thanks for any advice! Here is the code:
tell application "Finder"
set visible of every process whose visible is true and name is not "Finder" to false
close every window
end tell
set volume output volume 75
tell application "iTunes"
set currentVolume to sound volume
if player state is playing then
stop
back track
end if
play track "The Promise"
set player position to 6
end tell
delay 4
tell application "Safari"
activate
if (count of windows) is 0 then -- Remove "if" statement if you don't want to make a new window if there is none
make new window at front
end if
open (POSIX path of (path to home folder)) & "/Desktop/beMine/beMine.swf"
tell application "System Events"
tell process "Safari" to keystroke "f" using {command down, control down}
end tell
end tell
I agree with Jerry Stratton's comment that it could be an accessibility issue. However it also could be that you are issuing the keystroke command before Safari is ready to accept it. If it's opening a file then it could be busy and miss the keystroke command.
Also, I would move the system events code outside the Safari code and also just tell system events, rather than the Safari process, to perform the keystroke command. Try this as the Safari and System Events parts.
NOTE: I can't get Chrome to open a file either.
tell application "Safari"
activate
if (count of windows) is 0 then -- Remove "if" statement if you don't want to make a new window if there is none
make new window at front
end if
open (POSIX path of (path to home folder)) & "/Desktop/beMine/beMine.swf"
end tell
tell application "Safari" to activate
delay 1
tell application "System Events"
keystroke "f" using {command down, control down}
end tell
Most likely you’ll need to allow your standalone application to use System Events. At some point you needed to do that for Script Editor; you’ll need to do the same for your standalone app.
You’ll find the option in System Preferences under Security & Privacy, then Privacy, and then Accessibility. There’ll be a list of apps, and your app is probably listed there without a check for “Allow the apps below to control your computer.”
You may need to use the “+” button to add your app to the list.
I have verified that I can use this simple script to make Safari full-screen; it will work if the app is given permission under Accessibility, and it will silently fail if not.
tell application "Safari"
activate
end tell
tell application "System Events"
tell process "Safari" to keystroke "f" using {command down, control down}
end tell
This is Yosemite, Mac OS X 10.10; it may be different in other versions of Mac OS X.

Applescript: How to get window count of a process in all spaces?

Updating Microsoft Office to the newest version caused a pop over error to occur every few hours. "Mail could not be received at this time." Only restarting the app makes the error go away. Many people seem to have this problem with no resolution so I (a windows programmer) decided to write my first AppleScript.
First I tried to get the count of windows for Office:
tell application "Microsoft Outlook" to display dialog (count of windows)
returns 1 which is no good. Does this mean the pop over dialog isn't considered a window by OSX? Hmm. Seems unlikely.
Second I tried to get the window count from the process:
tell application "System Events" to tell process "Microsoft Outlook" to display dialog (count of windows)
returns 2. Great. Window 1 is the one I need and I write the script, run it, and works perfectly ... until I change from the space Outlook is in to a different space. From the new space count of windows returns 0. On further research it seems the spaces module is not included in Lion for AppleScript.
Anyone know how I can get a count of the process windows in all spaces? Is there another way to detect the pop over?
You may need to activate the application:
activate application "Microsoft Outlook"
tell application "System Events"
tell process "Microsoft Outlook"
if accessibility description of window 1 is "alert" then
beep
-- enter rest of your code
end if
end tell
end tell

Applescript/Photoshop: Create new layer with image

How can I create a new layer in a document with an image in that layer? I am using Pohotoshop CS5 and AppleScript.
I know how to make a new layer like this:
set newLayer to make art layer with properties {name:"LayerA"}
Just don't know how to put an image in it.
Thanks.
If you need it copied straight from a file, that's more complicated, and requires to open up a different app (Preview) and copy it from Preview. This may help:
set this_picture to choose file
tell application "Preview"
activate
open this_picture
end tell
tell application "System Events"
tell process "Preview"
keystroke "a" using command down
keystroke "c" using command down
end tell
end tell
tell application "Preview" to quit
That asks for an image, opens Preview, selects all of the image, copies it, and then quits.
To then paste it into Photoshop:
tell application "Adobe Photoshop CS5"
activate
end tell
tell application "System Events"
tell process "Adobe Photoshop CS5"
set newLayer to make art layer with properties {name:"LayerA"}
keystroke "v" using command down
end tell
end tell
And that's basically it! Hope that helped in some way.

AppleScript: How do I launch an application and then execute a menu command

I am trying to create a small applescript which will launch the DVD Player application and then resize it to its Actual Size. The code is listed below. When I run the code the DVD Player launches but it does not resize the window. What am I missing to get this to work?
Thanks,
Rob
do_menu("DVD Player", "View", "Actual Size")
on do_menu(app_name, menu_name, menu_item)
try
-- bring the target application to the front
tell application app_name
activate
end tell
delay 3
tell application "System Events"
tell process app_name
tell menu bar 1
tell menu bar item menu_name
tell menu menu_name
click menu item menu_item
end tell
end tell
end tell
end tell
end tell
return true
on error error_message
return false
end try
end do_menu
Have you looked at the dictionary for DVD Player?
There are properties for adjusting the size.
This will open it and go full screen:
tell application "DVD Player"
open
delay 2
set viewer full screen to true
end tell
Or there is the viewer size property which states:
viewer size (half/normal/double/max) : To set the the viewer size
So you could use this to go to Actual Size:
tell application "DVD Player"
open
delay 2
set viewer size to normal
end tell
Is that what you wanted to do?
I'm not in front of a Mac so I can't really test your code, but my suggestion is to try an existing and proven implementation of the same functionality, which uses recursion rather than nesting:
http://hints.macworld.com/article.php?story=20060921045743404
It's also possible that your delay 3 is not long enough for the DVD Player application to completely load before you start trying to script menu events. You could try debugging this by running two separate scripts and see if your menu-activation code works once the DVD Player app is loaded.

Resources