Applescript print by selecting preset and format - printing

I am trying to define the print parameters as presets with AppleScript.
I managed to open the pdf file with acrobat, open the print panel and define the number of copies, but then I was unable to "click" on the "Stampante..." (image 1) and subsequent (image 2) buttons. I do not find what are the commands to act on the window. Do you have any suggestions
#apro file con acrobat
#definire posizione la prima volta del programma
tell application "Adobe Acrobat Reader DC"
activate application
#apro file creare percorso per file su temp
open file "giungete:users:corrado:desktop:201.188_001.pdf"
#uso pulsanti per eseguire comando
tell application "System Events"
tell window "201.188_001.pdf"
#apro stampa
keystroke "p" using command down
delay 1
#vado copie
keystroke tab
delay 0.1
keystroke tab
delay 0.1
keystroke tab
delay 0.1
#definisco copie
keystroke "120"
delay 0.1
keystroke tab
delay 0.1
#do invio
#keystroke return
end tell
end tell
end tell
image 1
image 2

The example AppleScript code, shown below, was tested in Script Editor under macOS Monterey with Language & Region settings in System Preferences set to Italiano — principale and Inglese (US) and worked for me without issue1.
1 Assumes necessary and appropriate settings in System Preferences > Security & Privacy > Privacy have been set/addressed as needed.
Assuming you are Italian, and with no disrespect intended, I am not sure how well you will understand my answer or why I coded the example AppleScript code in the manner I have, however, I will try to explain some of it.
If you have a document opened in Adobe Acrobat Reader DC and you bring up the Print dialog box, it is a modal window and as such can simply be addressed as window 1 and no need to necessarily use window "Print" in general. The same goes for e.g. window "201.188_001.pdf", it can simply be addressed as window 1, but to just print an opened document the document window does not need to be relevant in my example AppleScript code because of how it is coded.
As there are multiple pop up button being clicked on the second |Print| window I wrapped the code in a handler so they can be clicked by number or name and number or name of the menu item. Keep in mind that by number the menu separators count as an incremented number.
I am using a choose file command to select the target PDF document to open and print in Adobe Acrobat Reader DC. You can of course choose not to use it and just set the print thisFile command to e.g.: print file "giungete:users:corrado:desktop:201.188_001.pdf"
I have added comments through the example AppleScript code to help explain what is happening.
Example AppleScript code:
property |Copies| : "120"
property |Print| : "Stampa"
property |Show Details| : "Mostra dettagli"
set thisFile to ¬
choose file of type "com.adobe.pdf" with prompt ¬
"Choose a PDF document:" default location ¬
(path to documents folder) without invisibles
tell application id "com.adobe.Reader"
activate
ignoring application responses
print thisFile
end ignoring
end tell
tell application id "com.apple.systemevents"
tell window 1 of application process "AdobeReader"
-- ## First |Print| window. ##
repeat until its name is |Print|
delay 0.01
end repeat
-- # Set the number of copies to print.
set value of first text field of group 1 to |Copies|
-- # Clicking the |Printer...| button causes a
-- # ~5 second delay, therefore tab to it instead.
-- # Tested in macOS Monterey and it took 18 tabs
-- # from the default opening of the |Print| window,
-- # however, it needs to be checked manually in
-- # other versions of macOS first.
repeat 18 times
key code 48 -- # tab key
delay 0.01
end repeat
key code 36 -- # enter key
-- # Wait a moment for the second |Print| window.
delay 1
-- ## Second |Print| window. ##
-- # Make sure second |Print| window is expanded.
if (the name of its button 2) is |Show Details| then
click button 2
delay 1
end if
-- # Click and select on Preset:
my clickPopUpButtonMenuItem(2, 1)
delay 0.25
-- # Click and select on Layout:
my clickPopUpButtonMenuItem(3, 1)
delay 0.25
-- # Click the Print button on the second |Print| window.
click button 4
delay 0.25
-- ## First |Print| window. ##
-- # Click the Print button on the first |Print| window.
-- # Leave commented until testing is finished.
--click button 4
end tell
end tell
-- # Handler #
on clickPopUpButtonMenuItem(PopUpButton, MenuItem)
-- # PopUpButton - Can be either an integer or the name.
-- # MenuItem - Can be either an integer or the name.
-- # MenuItem - Menu separators count as an incremented number.
tell application id "com.apple.systemevents"
tell window 1 of application process "AdobeReader"
click pop up button PopUpButton
click menu item MenuItem of menu 1 of pop up button PopUpButton
end tell
end tell
end clickPopUpButtonMenuItem
Notes:
As previously mentioned I chose not to click the Printer... (Stampante...) button because of the ~5 second delay if clicked. I believe the delay is caused because the second |Print| window opens and it has to time out because the button clicked it is from the first |Print| window which is now actually window 2, not window 1, and this is why tabbing makes more sense to avoid the delay.
I also tested the example AppleScript code in macOS Catalina and it was 17 tab stops to the Printer... (Stampante...) button, not 18 like in macOS Monterey.
Keep in mind that the number of tabs will be different if you change any of the other setting in the first |Print| window and it was based on your "image 1" link in that the only default you changed was the number of copies. You can always choose to click the Printer... (Stampante...) button instead and wait the ~5 second delay. It would be click button 2 instead of the repeat loop.
UI Scripting is kludgy and prone to failure and can break easily from one version of macOS to another as Apple and developers continually changes things, e.g. the hierarchical UI element structure. Case in point, 17 tabs in macOS Catalina vs. 18 tabs in macOS Monterey in this particular use case, the first |Print| window in Adobe Acrobat Reader DC.
Add-on to address request in comment
Even though the question originally focused on Adobe Acrobat Reader DC, nonetheless, as the author of the OP asked in comments about doing it in Preview, here is some example AppleScript code for use in macOS Monterey and Preview.
I thought it would be an interesting contrast to the different hierarchical UI element structure of the Print dialog box between the two applications to under the same version of macOS and how fragile UI Scripting can be preforming the same basic task between two different applications. While this would work with Preview in macOS Big Sur and macOS Monterey, it will not in macOS Catalina as the hierarchical UI element structure for the Print dialog box differs slightly, as there is no splitter group 1 of sheet 1 of window 1.
Example AppleScript code:
-- # Example AppleScript code for use in macOS Monterey and Preview.
property |Copies| : "120"
property |Print| : "Stampa"
property |Show Details| : "Mostra dettagli"
set thisFile to ¬
choose file of type "com.adobe.pdf" with prompt ¬
"Choose a PDF document:" default location ¬
(path to documents folder) without invisibles
tell application id "com.apple.Preview"
activate
open thisFile
end tell
tell application id "com.apple.systemevents"
-- launch -- # Used in an attemp to workaround a bug.
-- # Used to see the full large print dialog if Preview opens
-- # the document too tight on the left side of the screen.
tell window 1 of application process "Preview"
set currentPosition to its position
if item 1 of currentPosition is less than 70 then ¬
set its position to {70, item 2 of currentPosition}
end tell
-- # Bring up the Print dialog box.
keystroke "p" using command down
-- # Wait until the Print dialog box is ready.
repeat until exists button 1 of ¬
splitter group 1 of sheet 1 of window 1 of ¬
application process "Preview"
end repeat
tell splitter group 1 of sheet 1 of window 1 of application process "Preview"
-- # Show Details if necessary. (Mostra dettagli)
if exists button |Show Details| then
click button |Show Details|
delay 1
end if
-- # Printer: pop up button. (Stampante:)
click pop up button 1
click menu item 1 of menu 1 of pop up button 1
-- # Preset: pop up button.
click pop up button 2
click menu item 1 of menu 1 of pop up button 2
-- # Copies: text field. (Copie:)
set value of text field 1 to |Copies|
-- # Paper Size: pop up button. (Dimensioni pagina:)
click pop up button 3
click menu item 5 of menu 1 of pop up button 3
click menu item 2 of menu 1 of menu item 5 of menu 1 of pop up button 3
-- # Preview pop up button (By default.) (Anteprima)
click pop up button 4
click menu item 1 of menu 1 of pop up button 4
delay 1
-- # The following will vary based on menu selection of pop up button 4.
tell group 3
click pop up button 1
click menu item 1 of menu 1 of pop up button 1
-- click pop up button 2
-- click menu item 1 of menu 1 of pop up button 2
-- click pop up button 3
-- click menu item 1 of menu 1 of pop up button 3
end tell
-- # Print button. (Stampa)
-- click button 4 -- # Or click by name.
click button |Print|
end tell
end tell
Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

Thanks for the answers. I followed your advice I am clear to me the command to use the problem is what the window opens is called!
Example link
if not (exists (1st window whose value of attribute "AXIdentifier" is "MessagesPreferencesWindow")) then
Then Identifies the window and now with a new version of messages the menus changed but work
this works !!! link
I always get and only
System Events ha trovato un errore: Impossibile ottenere window "201.188_001.pdf – 1 pagina" of window "201.188_001.pdf".
I downloaded ui browser and found the correct path but I always get error
thanks corrado

Related

is there any atom style file tree close and open functionality available for vscode? [duplicate]

It'd be handy if there was a keyboard shortcut for hiding and showing the sidebar. Sublime has cmd+k+b and it's a quick way of gaining some screen real estate when you need it. Anybody know if this exists or if the user can add it manually to VS Code?
The command can be triggered via Ctrl+B on Windows and Linux or Cmd+B on the Mac.
There are 3 bars on the side, 2 left and 1 right:
the activity bar with 5 buttons
the primary sidebar toggled by clicking any of the activity bar buttons.
the minimap
All of these hotkeys and more (e.g. the terminal & output panel, Ctrl+J) are now visible through the View (Alt-V) and View>Appearance menus:
The activity bar has no toggle hotkey by default, but you can assign one like this:
{
"key": "ctrl+alt+b",
"command": "workbench.action.toggleActivityBarVisibility"
},
Or hide completely with "workbench.activityBar.visible": false
The sidebar toggle hotkey is Ctrl+B by default, but may be overridden by e.g. vim plugin, here's how to enforce or change it:
{
"key": "ctrl+b",
"command": "workbench.action.toggleSidebarVisibility"
},
The minimap can be hidden with "editor.minimap.enabled": false and toggled with editor.action.toggleMinimap since vscode 1.16.
And with the Sidebar-activity toggler extension, so you toggle both activity and sidebar together with one key mapping to sidebar-activity-toggler.toggleSidebarAndActivityBar
To Hide the 5 button Activity Bar we can now:
View -> Hide Activity Bar
This is in vscode 1.9, not sure which version it was introduced in.
As Benjamin Pasero's answer states you can use:
Ctrl+B on Windows and Linux
⌘ Cmd+B on the Mac.
but sometimes you have another keyboard shortcut with ⌘ Cmd+B, in my case I had it to format some React code. To reverse that you can use the following:
Code > Preferences > Keyboard Shortcuts (⌘+K ⌘+S) then search for B and disable the other shortcut command.
You can also change the it and put which ever shortcut you want, just search for Toggle Side Bar Visibility like this:
Just in case you be intended for hiding the right lateral "sidebar", also called minimap, there is no shortcut. But you can configure the settings with:
{"editor.minimap.enabled: false"}
One can also hide the activity bar with the following setting in settings.json:
"workbench.activityBar.visible": false
To hide/show the side bar:
Ctrl+B on Linux and Windows.
⌘ Cmd+B on Mac.
No need to edit Settings.json directly
Do the following:
Open the Keyboard Shortcuts by pressing ctrl+k & ctrl+s
Search: "Toggle Activity Bar Visibility"
Enter the keyboard shortcut
Done!
Activity bar visibility in visual studio code
Mac users,
⌘ + B or
⌘ + 0 - Worked Perfectly
In the VS code version 1.43, you can hide or show the side menu or activity bar by going under the 'VIEW' tab in the nav bar in the top margin of VS CODE(called the 'Menu Bar'). Go to View => Appearance, there you can check or uncheck different nav bars to show/hide each one.
If you have the top bar (Menu Bar) currently hidden press 'alt' key to bring it back then follow above instructions to check it to keep it there permanently if desired.

XLForm multi level selectors

I'm working on a very old iOS project that is using XLForm. I have to support a dynamic screen flow such as this attached
As XLForms is no longer on active development, I thought of asking the question here.
I've tried using XLFormOptionsObject and using a formSegueIdentifier to fully go custom but has not been that much helpful. If anyone has experience on a similar type of implementation using XLForms, any advice is really appreciated.
Side question;
I can intercept the Screen's C selection on Screen B using formRowDescriptorValueHasChanged, but how do I then manually pass that back to Screen A to update it's value?
Screen A
- Select Option > (tap pushes to Screen B)
Screen B
- Option 1 (tap selected option 1, pops and updates screen A row value)
- Option 2 (Same as option 1)
- Grouped Options > (tap goes to screen C)
- Option 3 (Same as option 1)
...
Screen C
- Option 1 from Grouped options (tap selects option 1, pops Screen C & B to go to A and updates screen A's row value)
- Option 2 from Grouped options (same as above)
...

How do I change Atom ctrl-tab to not show pane?

In Sublime when cycling through tabs using ctrl-tab it opens and shows the file as I cycle through them. In Atom it shows a pane / list of the recently viewed files. I want to turn this off and just have it cycle through the files and display them as I press ctrl-tab like Sublime. How do I do this?
Go to File > Keymap...
Enter in the following code:
'body':
'ctrl-tab': 'unset!'
'ctrl-tab ^ctrl': 'unset!'
This should disable the pane feature completely.
If you want to cycle through the tabs, you press CTRL+PAGEDOWN for left to right; and CTRL+PAGEUP from right to left.
If you want to change the keybind entirely, as in you want to use CTRL+TAB to cycle through the tabs, you can insert this snippet into the Keymap:
'body':
'ctrl-tab': 'pane:show-next-item'
Move tabs settings (Settings > Packages > Tabs)
and uncheck 'Display MRU Tab Switching List'

Dismiss alert on initial launch on iOS simulator

I'm working on the automated UI tests for my app and I'm having trouble when trying to set up the environment for running the tests. The plan is roughly this:
build the application
shutdown simulator if running
erase the simulator to make a clean install
install my app on the simulator
run UIAutomation tests
Everything is working except when the application is launched by instruments to execute the tests, the alert appears to ask if the user allows notifications. This is all as expected, but I can't find the way to get rid of the alert.
Things I have already tried:
creating onAlert as a first thing in my test script, in case it appears before the my alert callback is defined
delay the target by 5 seconds in case the tests actually run even before the UI of the app is visible in the simulator
I also went through all the permutations of the above that can be found on SO, I never get my onAlert callback invoked, no matter what I do. So another thing I tried was:
try dismissing the alert with applescript
The script I wrote:
tell application "System Events"
tell process "iOS Simulator"
set allUIElements to entire contents of window 1
repeat with anElement in allUIElements
try
log anElement
end try
end repeat
end tell
end tell
and it displays:
static text “MyApp” Would Like to Send You Notifications of window iOS Simulator - iPhone 6 - iPhone 6 / iOS 8.1 (12B411) of application process iOS Simulator
static text Notifications may include alerts, sounds, and icon badges. These can be configured in Settings. of window iOS Simulator - iPhone 6 - iPhone 6 / iOS 8.1 (12B411) of application process iOS Simulator
UI element 3 of window iOS Simulator - iPhone 6 - iPhone 6 / iOS 8.1 (12B411) of application process iOS Simulator
Looks like the buttons are placed inside the "UI element 3" but I can't retrieve any elements from inside it, let alone clicking on it. So I checked with Accessibility Manager:
It sits there as one of the children, the other ones are notification title and message. But when I go to that element, it is highlighted and I see this:
It is identified as generic element, it doesn't have any children...
The interesting thing is when I choose the OK button in the Accessibility Inspector, I can actually see it's a child of the window, yet it is never listed:
Can someone please shed some light on what is going on here? How can I press that button with Applescript?
If you are doing automation using Instrument, the you will need to register callback (onAlert) for performing any action on alerts.
But the problem in your case is that the alert appears before your script actually start executing and at that time no callback is registered for alert.
So if the alert can come with a delay of around 10 sec when you start application, then only it can be handled. But this can only be controlled through source code and not by your Automation code.
So only option which is left is you need to manual dismiss the alert once fresh application is installed
I am also facing same problem and found it to be a limitation of the tool
There are too many limitaion of this tool and thats why i shifted to UFT
I had a similar problem. I just wanted position of the last control on the alert. So I came up with following piece of code:
on get_simulator_last_object_rect(simulator_index)
tell application "System Events"
set ProcessList to (unix id of processes whose name is "iOS Simulator")
set myProcessId to item simulator_index of ProcessList
tell window 1 of (processes whose unix id is myProcessId)
-- Forcefully print the UI elements so that Accessibility hierarchy is built
UI elements
-- Then wait precisely to let the Accessibility view hierarchy is ready
delay 0.5
set lowest_label_lowest_position to 0
set _x to 0
set _y to 0
set _width to 0
set _height to 0
repeat with element in UI elements
set {_x, _y} to position of element
set {_width, _height} to size of element
set current_control_lowest_position to _y + _height
if current_control_lowest_position > lowest_label_lowest_position then set lowest_label_lowest_position to current_control_lowest_position - _height / 2
end repeat
return {{_x, _y}, {_width, lowest_label_lowest_position}}
end tell
end tell
end get_simulator_alert_ok_button_position
I have a desktop app to control my actions. I use this apple script in my Desktop app to get the frame of the last control. Now that I have the frame, I create a mouse event and perform click on the frame, after activating the simulator.
Although I have not yet tried, but I am pretty sure that you can create mouse events from apple script and perform click on the frame / center of the frame.
Hope this helps.
Thanks,
RKS

Xcode 4 keyboard shortcut to switch build target destination

Is there a keyboard shortcut in Xcode 4 to switch the build target destination; that is, to switch from simulator to device and vice versa?
There is, is called Destination>select next destination. Go in the prefs in xcode and then in the key bindings tab, search for that, it will show what key it is set at.
For me, is cmd+alt+ctrl+] and [ to switch. Is quite useful, saves a few seconds.
In Xcode 4.6, the shortcut is ctrl+option+cmd+[ and ctrl+option+cmd+]
You can use ctrl + cmd + [ or ctrl + cmd + ] to select scheme, or use ctrl + cmd + [alt] [ or ctrl + cmd + [alt] ] to select product
Or you can just search in the preference panel of key bindings for more information
You can write applescript and bind it to some hotkey (using FastScripts for example - free up to ten bindings).
Next script will click for you on your scheme button in the Xcode toolbar:
tell application "System Events"
tell process "Xcode"
click ((pop up buttons of list 1 of group 2 of tool bar 1 of front window) whose description is "Active Run Destination")
end tell
end tell
then you can just use Up/Down to switch destination.
Note that you need to enable access for assistive devices under the SystemPreferences -> Accessibility
You can go to the edit scheme menu with cmd+< which is actually cmd+shift+.
You should know
Build: cmd+B
Run: cmd+R
Test: cmd+U
Profile: cmd+I
Analyze: shift+cmd+B
But there isn't a command just to switch between the iPhone simulator, iPad simulator, and all of your external.
I have a slightly different problem but it might help you as well.
I have only one physical device which always stays at the top.
Its super simple to select top list device as a target.
Do:
pops up the list for target devices
CTRL + SHIFT + 0
takes you to the first device
CMD + UPARROW
selects that device
SPACE
Apple Script goes:
tell application "Xcode" to activate
tell application "System Events"
tell process "Xcode"
keystroke "0" using {control down, shift down}
delay 0.55
keystroke (ASCII character 29)
delay 0.55
keystroke (ASCII character 30) using command down
delay 0.55
keystroke (ASCII character 32)
delay 0.55
keystroke "r" using command down
end tell
end tell
Riffing on off Comradsky, the answer is then:
Cmd+Shift+, then Tab then Up/Down
You can also option-click on the scheme in the title bar to directly open the settings for the scheme (whereas a normal click opens the context menu that displays a list of all the schemes).
Show Destinations
To bring up the list of destinations use ⤵︎
^ + Shift + 0

Resources