0

I am new to Applescript and MACs although my first computer was an Apple II Plus and I programed in Apple Basic and Assembly.

I am using it to create a "Silent" alarm button.

We have a system in place that via a URL call will send a message to a select group of computers, in this case the ones used by our security officers.

I wrote a similar one for PCs using the AutoIT scripting language. When some one clicks on this program, as far as anyone watching the screen is concerned, nothing happens. It is 100% silent. But unseen by anyone looking at the PC screen, IE was launched minimized and hidden, a custom URL string, with an embedded message, is opened and then IE is closed. The security officers computers get a message from the message system, Informacast, and security responds accordingly. At no time is anyone watching the PC screen aware that anything has happened. It is all "Silent". Just like a silent alarm in a bank.

My MAC version, written in Applescript is working well except that the call to Safari can be seen on the screen when it takes place. It is only there for a few seconds as the URL is loaded, and then the Safari window is closed, but that few seconds is a few seconds to much and anyone watching the screen will know something happened when the alarm was pressed. I need to prevent anything from showing when Safari is launched. I need to make it "Silent".

The part of the script that opens Safari and loads the URL is shown below...

tell application "Safari"
launch
open location AlertURLString (This is the variable that has the URL and embedded message in it)
delay 1
close window 1
end tell

I have tried placing the following line in "Tell" routine in various places, before "launch" after "launch" before "open location" and after etc., but I still see a blip of the Safari window as it loads the URL string.

set miniaturized of window 1 to true

I also played around with variations of the following line but got an Applescript error every time.

tell application "System Events" to set process "Safari" to false

One more thing, it is possible that Safari or some other program could be open, maybe not full screen etc when this script is run and it is important that it not be closed or changed in any way that would clue some one in to the fact that something was happening on the system after the "Alert Button" is pressed. The "set miniaturized" line depending on how it was used would minimize the window which of course we don't want.

Again what I need is to be able to launch the URL 10000% silently.

Thanks in advance to all who are able to try and help,

Ralph

2
  • 10000% hmmmm...
    – Deesbek
    Commented Aug 7, 2014 at 23:24
  • You could try a headless browser like Selenium.
    – camursm
    Commented Feb 2, 2023 at 20:02

2 Answers 2

5

You won't be able to do it in AppleScript : Safari only does something on open windows.

You should definitely look at Command line scripts like curl.

The AppleScript to call a shell command takes the form:

set variableName to do shell script "command"

So using your AlertURLString you'd want something like:

set curlOutput to do shell script "curl '" & AlertURLString & "'"

See the curl man page for more details on how to use curl to do things like POST and PUT calls or attach payloads to the calls and what not. It is incredibly powerful.

3
  • Right tool for the right job and curl is the right tool here for certain!
    – Ian C.
    Commented Aug 7, 2014 at 23:22
  • I was about to say curl also Commented Aug 8, 2014 at 0:01
  • Thanks to all, Ian, Matthieu, Scott, Deesbek, and anyone else who has tried to help. Curl does seem to be the answer. However, the syntax given did for using it did not work. I had another example I was able to use to get it to work but then my "message" is now limited to 255 characters. On the PC I don't have that limit. I am not sure this response is going to all who have helped, nor can I use the 'return" key so I will try another option to explain more. thanks again for all who helped.
    – Ralph
    Commented Aug 8, 2014 at 18:09
0

if you look at the curl manpage (man curl) it doesn't seem to have a limit on url size. You may want to look into using the -d or --data options.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .