Confirm a popup box outside of the desktop environment? - batch-file

I have a script that produces a popup that requires the user to click [Ok]. I have another script that can automate this by using SendKeys, however how can this be done when the the script needs to be run when the user is logged off? The script seems to rely on the desktop environment being active.

Check out a tool like nircmd that can send a BM_CLICK message directly to the button instead of relying on UI/keypresses.
Assuming your message box uses a standard OK button and you have nircmd.exe in the same folder as your script (or in the system path), the following statement should click it:
With CreateObject("WScript.Shell")
.Run "nircmd.exe dlg """" ""The Popup Title"" click ok"
End With
If the title of the message box isn't unique, pass the process name as well:
With CreateObject("WScript.Shell")
.Run "nircmd.exe dlg ""someprocess.exe"" ""The Popup Title"" click ok"
End With

Related

How can I tell my AppleScript to ignore renamed files?

I put together a simple AppleScript that automatically opens new files, that are added to a specific folder. This works great! Problem is, if I rename the new file, then automator runs and re-opens the document. The naming convention is limited by the scanner, but is:
2022-12-21-191532
Year-Month-Date "-"
Random number (timestamp maybe?)
".pdf"
Is there a way to make my script only run on new files and ignore files that are renamed?
The settings are "AppleScript" & "on adding"
on adding folder items to this_folder after receiving added_items
delay 30
try
tell application "Finder"
--get the name of the folder
set the folder_name to the name of this_folder
--go to the desktop
activate
open this_folder
open added_items
reveal the added_items
end tell
end try
end adding folder items to
I tried googling this, but all I keep finding are examples on how to automate renaming files.
Here is an AppleScript solution which you may find useful.
This following AppleScript code will display a dialog allowing you to enter a new file name to rename your currently selected file, in Finder, to the new name. Before it renames the file, it will temporally disable all Folder Actions, then renames the file, then re-enables your Folder Actions. This way, simply renaming your file wont trigger your Folder Actions to run.
tell application "Finder"
if (count of (get selection)) ≠ 1 then
tell current application
activate
display dialog "Please Make Sure Only One File Is Selected" buttons ¬
{"OK"} default button "OK" giving up after 4
end tell
return
else
set nameOfFile to name of item 1 of (get selection)
tell current application
activate
set newName to text returned of ¬
(display dialog "Rename file " & nameOfFile & ¬
" to..." default answer "New File Name" buttons ¬
{"Cancel", "OK"} default button 2 cancel button 1 with icon 1)
end tell
set renameThisFile to item 1 of (selection as alias list)
end if
end tell
tell application "System Events"
if folder actions enabled then set folder actions enabled to false
delay 0.1
set name of renameThisFile to newName
delay 0.1
if not folder actions enabled then set folder actions enabled to true
end tell
What you could do is take the code from above, then in Automator create a new Quick Action, add a Run AppleScript command to the workflow and insert the AppleScript code.
After you name and save your new Automator Quick Action, you can then shoot over to System Preferences/Settings and assign it a keyboard shortcut.
Now anytime you are in Finder, you can rename your currently selected file with your new keyboard shortcut and you will not trigger your Folder Actions.
I have a Folder Action that automatically adds the tag "Aquarium" to any item added to this one specific folder. This following animation demonstrates me first renaming "file 1.txt" to "file.txt" in Finder (the normal way). As you can see, simply remaining that file did trigger the folder action which automatically added the tag to the renamed file. Then, I used my new keyboard shortcut to rename the selected file "file 2.txt" to "xxx" in Finder, without triggering the Folder Action to add the tag to the file after renaming it.

With Appium how to click the "home" button or launch the home screen in ios simulator?

I am trying to launch the "home" screen in ios simulator with Appium, but failed to find any api to do that .
Any suggestions would be of great help .
There is a limitation in ios.We cannot send key code to press home button in ios and because of this limitation we cannot automate home button.But in android we can do that using keycodes.In iOS automation we cannot do that.
As per link:
https://github.com/appium/java-client/releases/tag/v5.0.0-BETA6
One enhancement has been added which is:
[ENHANCEMENT] iOS XCUIT mode automation: API to run application in background was added.
Maybe you can try using Java-Client v5.0.0-BETA6 and try out this API
Thanks guys for responding ,seems like there is no way the home screen can be launched , even java robot keys "command+shift+home" doesn't work .
So I had to write one apple script, when called will launch the home screen in the simulator .
it's here
try
tell application "System Events"
if exists process "Simulator" then
tell process "Dock"
delay 2
set frontmost to true
activate
tell list 1
try
perform action "AXShowMenu" of UI element "Simulator"
delay 2
#click accssibilitytitle "Open" of menu item of menu1 -- up arrow
key code 126 -- up arrow
key code 126 -- up arrow
key code 126 -- up arrow
key code 126 -- up arrow
key code 126 -- up arrow
-- key code 125 -- down arrow
delay 2
key code 36 -- return key
on error errMsg
if errMsg contains "Simulator" then
log "Simulator is not present in the dock... To run the automation, add Simulator in the dock and try again!!!"
return
else
log errMsg
return
end if
end try
end tell
end tell
end if
end tell
on error errMsg
log errMsg
end try
tell application "System Events" to tell process "Simulator"
tell menu bar item 5 of menu bar 1
delay 3
click
delay 5
click menu item "Home" of menu 1
delay 3
end tell
end tell
It is able to successfully bring the simulator in focus by right click on the simulator icon present in dock and then selecting "Home" from the "Hardware" menu (which is menu 5) .
During in test your app , you can run your app in background an get back.
to do this you have to add
protected IOSDriver iosDriver;
after definition
#Test
#Description("Some Description")
public void testSearchZeroResultAndHomeBack(){
// run app in background for 5 seconds
iosDriver.runAppInBackground(5);
Assert.assertTrue(isTextDisplayedOnPage("0 ilan"));
}
// run app in background for 5 seconds
iosDriver.runAppInBackground(5);
On your current appium driver you need to use following code. driver_iOS is object of appium driver:
driver_iOS.ExecuteScript("client:client.deviceAction(\"Home\")");
If you want you can quit this driver once your work is done i.e. driver_iOS.Quit();
I hope it will work for you.

How to reset pgAdmin4 GUI?

I tried Ctrl++, Ctrl+-, then pgAdmin4 v1.1 (on Windows 10 Pro x64) error. Then, I tried re-install, but error still exist:
How to fix this error?
RESET Layout :
1.The pgAdmin menu bar displays the following selections: File, Object, Tools, and Help.*
Use the File menu to access the following options:
File -> Reset Layout
OR
Open the browser console and run following :-
pgAdmin.Settings.show()
This should pop up dialog: "Are you sure you want to reset the current layout? ..."
I had this error too. The menu item "Reset Layout" was not visible. Actually NO menu item was visible, so I dug up the actual method that is triggered by the "Reset Layout".
To fix, do this:
Open the browser console
Paste this JavaScrips code: pgAdmin.Settings.show()
This should pop up dialog: "Are you sure you want to reset the current layout? ..."
Like a web-page, press Ctrl + 0 for reset zoom level.
Neither of the mentioned methods worked for me to reset the pgAdmin layout. Finally, what helped, was to delete the ..\AppData\Roaming\pgAdmin\ directory and install again.
go to file option and select reset layout.
https://www.pgadmin.org/docs/pgadmin4/dev/pgadmin_menu_bar.html
Zoom in: Ctrl + Shift + +
Zoom out: Ctrl + -
For the pgAdmin desktop app, I deleted the .pgadmin (hidden) folder from my Home Directory on my Unix machine. Using the command:
rm -rf ~/.pgadmin
But be aware as it will delete all your saved connections too.
..\AppData\Roaming\pgAdmin\runtime_config.json
change prop "zoomLevel": 1,

Delete multiple files - Receive only one authentication prompt

I'm trying to create a script to delete multiple files in the same folder without having to authenticate twice. I've tried a bunch of things but I'm super new to AppleScript and I keep striking out. Any assistance is greatly appreciated.
set colorProfiles to (POSIX file "/Library/ColorSync/Profiles")
set coatedToDelete to "Pantone+ Solid Coated.csv"
set uncoatedToDelete to "Pantone+ Solid Uncoated.csv"
try
--Notification window with info
display dialog ("This script will automagically delete your outdated Pantone color books. Please make sure an admin is nearby to authenticate (twice) if prompted.") with icon note
--Deletes both Pantone+ .csv files
tell application "Finder"
delete file (coatedToDelete of folder colorProfiles)
delete file (uncoatedToDelete of folder colorProfiles)
end tell
--Successful deletion notification
display dialog ("The outdated color book deletion was successful!") buttons {"Great!"} with icon note
on error
--Error message notification
display dialog ("This script was unable to delete your legacy Pantone color books.") buttons {"OK"} with icon caution
end try
Use the shell command rm, it can delete multiple files in one line with one authentication. The difference to the Finder is that the files are deleted immediately instead of being moved to the trash folder.
set colorProfiles to "/Library/ColorSync/Profiles/"
set coatedToDelete to colorProfiles & "Pantone+ Solid Coated.csv"
set uncoatedToDelete to colorProfiles & "Pantone+ Solid Uncoated.csv"
try
--Notification window with info
display dialog ("This script will automagically delete your outdated Pantone color books. Please make sure an admin is nearby to authenticate (twice) if prompted.") with icon note
--Deletes both Pantone+ .csv files
do shell script "/bin/rm " & quoted form of coatedToDelete & space & quoted form of uncoatedToDelete with administrator privileges
--Successful deletion notification
display dialog ("The outdated color book deletion was successful!") buttons {"Great!"} with icon note
on error
--Error message notification
display dialog ("This script was unable to delete your legacy Pantone color books.") buttons {"OK"} with icon caution
end try

how to make a .bat file "activate" when the PC sleeps

Is there a way that I can make a batch program begin when I put my computer to sleep?
I would like to disable a USB port when I put my computer to sleep. Is this possible if so, how would I go a out doing so?
As this has not been marked as closed I am assuming the author has not been able to piece together the answer from the comments. This answer is derived from those comment hints and gives the detail that perhaps the questioner requires....
If you search for information on using the task scheduler to trigger on the sleep event you get to this page at Microsoft, which contains the following:
Input “Task Scheduler” in search box and press Enter
Click “Create task…” on the Task Scheduler---Action
Go to Triggers, create new triggers
On “Begin the task”, select “On an event”
Select Log to “system” , set “Source” to “Kernel-Power” , Event ID
is “42” and click “Ok”
Go to “Actions” and create a new actions
You can select “Start a program”, “Send an e-mail” and “Display a
message” on action as you need.
Save the task scheduler
On conditions tab, check the box “Wake the computer to run this task”. Click OK.
The information about using devcon.exe is on this microsoft page which shows the following command does the trick:
devcon disable *MSLOOP
You can either make a batch-file calling devcon, or have the task scheduler call devcon directly with the appropriate arguments.
Is that enough detail to explain the solution?

Resources