I literally only started using Applescript today trying to write macros for an audio program I use so I really don't know a lot and am stumbling through this.
All I need to do is monitor when a certain window is open within the software and then most importantly, when it closes.
When I export a file from my software, a window comes up image of window The window has no identifier other than the static text "Bouncing..." In the screenshot there is a cancel button, but this doesn't apply to every instance of the window (depends on what options are selected) so it's the only thing I have to work with.
So far I have this:
tell application "System Events"
tell process "Pro Tools" to set myvalue to value of every static text of front window
repeat with i from 1 to count of myvalue
if (item i of myvalue = "Bouncing...") then repeat
end repeat
delay 1
end repeat
end tell
Testing this with a popup instead of the repeat stating it has found the static text works. So I'm halfway there.
All I need to do is to repeat this entire process over and over until the window disappears. Obviously when "myvalue" is "Bouncing..." I need to go back to the start, collect the static text values from the window again and then only exit the loop when the static text value of "Bouncing..." doesn't exist.
Currently it seems to exit the loop before the window has closed
Thanks for any help given here, I've spent hours on this and I'm just not knowledgeable enough to figure it out.
Found another way around it. It seems it does default to "window 1":
try
tell application "System Events"
repeat while (value of first static text of window 1 of application process "Pro Tools" = "Bouncing...")
delay 1
end repeat
end tell
end try
Related
In Excel VBA, is it possible to change the window style of a shelled program?
Here's the situation in detail:
At the click of a command button, the user should be able to load a third-party scanning program. The software path and file are specified in a named cell called settings_scanningsoftware, as you can see below. However, I'm using the Shell program, which doesn't wait for the third-party software to load before continuing. If it did, my life would be easier. For that reason, I throw up a dialog box in Excel telling the user to wait for the software to load and then ready the item to be scanned before they click Ok. And, since I throw up a dialog box, I load the scanning program minimized so they can see the dialog box (instead of it being hidden behind the software window and they're wondering why nothing's happening). With me so far?
However, once they click Ok, I want Excel to give control to the scanning software and give it a regular-sized window. There's my problem: once the software is loaded minimized, I can't seem to change the window style to give it a regular window.
Here's my code:
On Error Resume Next
Dim ScannerShell As Integer
ScannerShell = Shell(Range("settings_scanningsoftware").Value, **vbMinimizedNoFocus**)
If (ScannerShell <> 0) Then
Dim MessageBoxValue As Integer
MessageBoxValue = MsgBox("When you're ready to scan the receipt, click Ok.", vbOKCancel, "Scan receipt")
If (MessageBoxValue = vbOK) Then
ScannerShell = Shell(Range("settings_scanningsoftware").Value, **vbNormal**)
AppActivate ScannerShell, False
SendKeys ("{TAB}{TAB}{TAB} ")
End If
End If
Notice I've got the vbMinimizedNoFocus bolded above so that the software loads minimized and the user can see the upcoming dialog box. Once they click Ok, though, the software's window should be normalized. But Excel won't do me that favour.
Is there a way to change the window style after it's loaded?
Never mind the SendKeys command. I put that in there to get the scanner to automatically scan once everything is in place (the key sequence is incomplete, but one problem at a time). I know SendKeys is not a great way of sending commands to a program, but I'll figure that out once I get this window style thing fixed.
Does anyone have any solutions for me? Thanks.
Is there any way to control 2 different safari browser windows with Applescript at the same time und switch between them? Something like a unique ID to be sure which commands are for which safari window.
something like...
tell application "Safari" id 1
activate
....
end tell
:-)
thanks for your help.-
Windows in AppleScript are code objects, so if you make a reference to one, e.g.:
tell application "Safari"
set aWindow to window 1 -- sets a reference to the current front window
end tell
AppleScript will remember that particular window even if you move it, hide it, put it in the background, minimize it... Until you reset the variable or close the window, you can be sure that aWindow will point to that particular window. In fact, this works the same for tabs. You can say:
tell application "Safari"
set aTab to tab 3 of window 1 -- sets a reference to the third tab of the current front window
end tell
and even if you move that tab to a different window, AppleScript should still track it. Likewise, if you have a window pointing to the Google Search engine, you can say:
tell application "Safari"
set aWindow to window "Google" -- sets a reference to the Google window
end tell
and then if you navigate to a different webpage, the variable aWindow will still point at the same window. Neat, huh?
So all you need to do is create a couple of variables for your two windows, and you can switch back and forth as you like:
tell application "Safari"
-- assuming you have a 'Google' window and a 'Yahoo' window open
set firstWindow to window "Google"
set secondWindow to window "Yahoo"
set URL of document of firstWindow to "https://stackoverflow.com"
set index of secondWindow to 1
set miniaturized of firstWindow to true
end tell
Windows are identified by their absolute Id. You can see ID's with :
tell application "Safari" to set myWindow to every window
It gives you list of all open windows of Safari like :{window id 4519, window id 4426, window id 4514}. There are 3 open windows !
However to switch between 2 Safari windows, you must use their number: 1 is the frontmost, 2 is behind, 3 is behind the 2,...
You can tell the System Events to make number 2 before number 1. Doing so, old 2 becomes 1 and the 1 becomes 2.
tell application "System Events" to perform action "AXRaise" of window 2 of process "Safari"
if you just have 2 windows, the line above will keep switching between your 2 Safari windows, each time making the second window the frontmost one.
I'm using some software called controllermate with allows you to customize the behavior of buttons on a keyboard or mouse. One of the 'building blocks' you can use in a particular function in an apple script. I would like to create a custom behavior for my mouse such that a certain button will execute CMD+C if something that can be copied is currently selected, but otherwise execute a different keyboard shortcut. It seems I will have to use an appleScript in order to determine whether text is selected, but after reading other some other people's solutions online I was unable to figure out how to implement it myself. Thanks for any help.
Here's a solution:
Put an empty string to the clipboard, do CMD+C, check the clipboard.
set the clipboard to ""
tell application "System Events" to keystroke "c" using command down
delay 0.2
set b to false
try
set b to (the clipboard as string) is not ""
on error -- error when the clipboard contains a custom type (like a copy in the Photos Application)
set b to true
end try
if b then -- the clipboard does not contains an empty string
-- *** script to execute a different keyboard shortcut ***
--tell application "System Events" to keystroke someChar using someModifier
end if
I have a Macro which takes 45 seconds to complete. When the macro starts I want a Countdown timer to pop up like a message box which will countdown until Macro completion. I have searched but so far cant find any answers to this. Is this possible?
As #Thrum correctly mentioned in his comment this is not possible with a message box.
A MsgBox is modal and therefore blocks the entire Excel application. Nothing else can happen / be done while that message box window is open and waits for you to close it. Actually, you can even make message boxes system-wide modal. In that case no other Windows application will respond unless you close that little message box in Excel (check the option vbSystemModal within the VBA help regarding MsgBox).
However, with forms on the other hand you have a choice. You can make the form not modal.
UserForm1.Show (False)
In that case the code continues to run in the background while the form is shown to the user and permits the running VBA code to make changes to the form while it is shown to the user.
here is my next question and i hope some one can help me :-)
Is it possible to position a msgbox in wsh/vbs?
alt text http://www.4freeimagehost.com/uploads/a9b04cde0527.jpg
I need the msgbox everytime in the foreground. I know that how to position a inputbox, but not a msgbox.
Thanks for help.
Greetings,
matthias
You cannot do that with a WSH MsgBox using VBS alone.
InputBox is the only build in dialog function that allows you to set a position.
You can use a WshShell.Popup and make it disappear after a few seconds, however it will be centered.
Edit; here is something using IE.
This is possible. Here is a link to a code sample (VB5, so it should work for you):
http://support.microsoft.com/kb/180936
Basically, you set up a hook so that your application gets a notification whenever you pop up a message box. Inside the handler, you move the message box to the desired location on the screen.