Using apple script to press the return key when prompted to connect to server - networking

Currently this is my delima. Once in a while a build agent will reboot. It needs to always stay connected to share on one of our servers. The idea was to tell finder to mount the volume, wait 2 seconds, and then press enter...since the user name and pssword are both part of the address when I enter it such as SMB://username:password#Server1/DFS it pops up the pasword dialog fully populated but I can't get applescript to recognize it, then press either connect or the return to say "Yes" login witht hat name and don't prompt me.
it worked fine when connecting at home to a synology device but it's not working when connecting to a server in the office.
tell application "Finder" to mount volume "SMB://username:password#Server1/DFS"
delay 2
tell application "System Events" to keystroke "return" -- key code 36
Any help for this seemingly simple step would be greatly apprecited.
I have looked ove the forums and found variou stratagies but they all relate to an application like Firefox or some other script aware app. I just need it to press enter when the password dialog comes up.

First of all the Finder is not needed to mount a volume, you can delete the tell block.
Secondly, if username and password are passed the volume is supposed to mount without a dialog. Maybe you could find the reason why it doesn't.
Nevertheless the password dialog belongs to the process SecurityAgent, you have to use (ugly) GUI scripting to press the button:
tell application "System Events"
repeat until exists process "SecurityAgent"
delay 0.5
end repeat
tell window 1 of process "SecurityAgent"
click button 2
end tell
end tell
The script waits until the window appeared, this is much more reliable than an hard-coded delay.

Looks like a possible XY Problem as I would expect a solution such as https://apple.stackexchange.com/a/698/204318 to work for you to directly mount the share:
mount -t smbfs //username:password#MACHINENAME/SHARENAME /SomeLocalFolderOfChoice
However, if you are really required to interact with the dialog, and as you asked about it, take a look at this tutorial (written in Python) for scripting up something:
detect missing connection
attempt connection
capture screen periodically
look for dialog box, else loop
error after a few seconds of failure
if dialog is detected, interact with it
input username and password
wait, then press return
check if connection worked after a small delay
success or failure
This type of strategy is very powerful for interacting with all sorts of different dialogs you may encounter and should be possible in AppleScript if you are much more familiar with it (or another scripting language).

If you are open to non-AppleScript solutions, then you might consider Keyboard Maestro, one of the best Mac automation tools available.
You said:
it pops up the pasword dialog fully populated but I can't get
applescript to recognize it, then press either connect or the return
to say "Yes" login witht hat name and don't prompt me.
You could probably do this very easily using Keyboard Maestro. Here's an example of the KM Actions to accomplish this.
If you'd like help with KM, please visit the forum at:
https://forum.keyboardmaestro.com/
I'm a big AppleScript/JXA user, but I often find it easier/quicker to use KM for many automation tasks. Of course, KM Macros can execute AppleScript, JXA, Shell Scripts, and other scripts easily.
You can try a full version of KM for free for 30 days.

Related

The Run button on PopSQL not working [greyed out]

The run button in PopSQL greyed out a while ago after I restarted my laptop. No matter how I tried I couldn't click on it. I re-checked, double-checked my queries but it still didn't work.
Please help.
First of all, check the following -
Your query - Check for semantic errors.
Your database connection - There may be some fault in the connection itself. Try connecting again with the database. Check if just above the tab where the connection is specified if you can see your database name like this -
If you have just installed MySQL in your laptop (or anyways, now you don't have any other option) -
Open run from Start Menu or press windows key + R.
Search for 'services.msc'.
In the search window, search for MySQL80. Double click on it to open.
You will notice that the service is either disabled (in startup type) or stopped in the service status.
Select Automatic or Automatic (Delayed start) in the select box of Startup type and click on apply. So that whenever your machine starts the MySQL service will start automatically in the background.
After that click on the Start button to start the MySQL service on your machine. It will take a few seconds to start.
Then click on apply and hit Ok. Then close the services window also.
Now try opening PopSQL you'll see that database connection has been corrected.
ENJOY!!!

How can I judge whether deep freeze is in frozen programatically?

Two problem here:
Just like the title, when Faronics' deep freeze is running at my computer, how can I find whether it is in frozen state programatically?
Deep freeze seriously influence my software update scheme, Is there any good idea to handle it?
Any answer is appreciated. thanks!
You can query windows event log for checking Deep Freeze frozen or thawed state.
When Deep Freeze is in Frozen state it will create an event log under
Event Logs > Windows > Application
Event Data : Frozen
When Deep Freeze is in Thawed state it will create an event log under
Event Logs > Windows > Application
Event Data : Thawed
I found it by searching the registry
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Faronics\Deep Freeze 6\DF Status
This will be either Frozen or Thawed as a string.
An oddity is the fact that it says Deep Freeze 6 in the registry but i have version 8 installed.
First Question:
Hold down the shift key and double-click the Deep Freeze icon. Alternatively, you can press CTRL+ALT+SHIFT+F6.
Enter your password and click OK.(ask the shop owner)
If you have not yet entered a password you should be able to click OK without entering a password.
The Boot Options dialog is displayed. That will tell you if it's active.
Second Question:
Deep Freeze is not optimized to handle updates. I've tried a few different solutions similar to Deep Freeze and found that Drive Vaccine was the most user friendly in terms of implementing updates. Something to keep in mind, as I know the handling of updates has been many people's biggest complaint about Deep Freeze.

How to capture stdout from a console application whose life cycle is very long by CreatePipe?

I tried to write an test application to capture the text from stdout of an 3rd console application.
I studied from many articles to use the CreatePipe API and have INDEED obtained the text AFTER the console application HAD FINISHED running.
I tried to make the console application keep printing something for more than 60 seconds, and the ReadFile funcion didn't return during this 60 seconds at all.
For the same purpose, I tried popen and fread, and everything went fine except the black console window created by popen.
Although the ReadFileEx and something about the overlapped I/O seems to be able to solve this problem but it's actually not.
Because the ReadFileEx required the file handle to be created to support overlapping, and this is always impossilbe because the file handle is created by the 3rd console application. It won't be under control unless we develop the console application by ourselves.
So is there any way to capture stdout from a 3rd console application whose life cycle is very long by CreatePipe?
Thanks in advance!
I finaly figured out the problem is the 3rd console application "MAC.EXE" doesn't invoke "fflush" after each progress output....
I manually append the fflush operation in the source code of mac.exe and the problem gets resolved.
So a new question is:
If the child process never call fflush and seldom print during running, how to read the content correctly?

Asterisk Music On Hold loop

I would need to be able to allow users to 'loop' through our MOH files.
Currently we have MOH set like this:
[moh]
mode=files
directory=/var/lib/asterisk/moh/custom
is there a way to allow users to go to next file from that directory by clicking number 1 on keypad?
Thank you
Only variant i see without rewrite of asterisk is just stop/start moh based on key pressed
See features.conf
http://www.voip-info.org/wiki/index.php?page_id=1483
You also can create custom application which stream file and other app which on key pressed do "next track" on that app, but that will result alot of CPU usage.
See streaming:
http://www.voip-info.org/wiki/view/Asterisk+config+musiconhold.conf

HKWorkoutSession isn't keeping app at front of Apple Watch

It has been stated that an app running a HKWorkoutSession will have special privileges over other watchOS 2 apps, so when a user looks at their Apple Watch, it will go to the view showing running a workout rather than the watch face.
Currently, on both my device and simulator, this is not the case. If I start a HKWorkoutSession and then leave for 5 minutes and then interact with either the Apple Watch, or the Watch Simulator, it presents the watch face.
If I then open my app, it appears to have been frozen, rather than terminated (which is what I imagine happens to other apps). As the UI will update when I need receive a response in my query.updateHandler. Also if I set it to provide haptic feedback every time my query.updateHandler receives a new HKQuantitySample it will do so, so the app must be running in the background in some form.
Has anyone else noticed this behaviour, and am I doing anything wrong, or expecting something I shouldn't?
Here is how I start my HKWorkoutSession:
self.workoutSession = HKWorkoutSession(activityType: HKWorkoutActivityType.Other, locationType: HKWorkoutSessionLocationType.Indoor)
self.healthStore.startWorkoutSession(self.workoutSession) {
success, error in
if error != nil {
print("startWorkoutSession \(error)\n")
self.printLabel.setText("startWorkoutSession \(error)")
self.printLabel.setTextColor(UIColor.redColor())
}
We're seeing that too, for the moment we've made sure 'opens last activity' is configured.
When the UI is active we start a dispatch_timer to request and process data in 1 second intervals.
Make sure you do any significant processing using the NSUserProcessInfo method though and pause the dispatch_timers whenever you are no longer active. You'll get crashes otherwise.

Resources