-1

I come from a Windows programming background and I need to replicate a simple Windows console application in the MAC OSX world. It's actually called from a daily script, but it needs to do the following: 1) Check a network file share for a specific file. 2) If that file exists, make a call to a web site URL with one query string parameter. That web site URL simply returns a YES or NO as a string back (no HTML markup tags are returned). 3) If Yes is returned, delete the file.

This is it, I am just starting to look and I see references to cocoa, x-code, swift. Which way to go and what would support specifically the getting a result back from a URL?

I need to be pointed in the right direction and anything else you wish to add to get me going would be appreciated. Thanks! I appreciate any help that will be forthcoming! Venturing into a whole new world.

Brian Edwards
  • 403
  • 6
  • 15
  • 1
    You don't need anything that you have tagged. You can open a Terminal window (CMD+Space and start typing "Terminal" and hit "Enter" when it guesses). Then use a `bash` script with `curl`. See http://stackoverflow.com/a/638980/2836621 – Mark Setchell Apr 12 '16 at 13:05
  • Thanks Mark, is there also the capability to get back a result from a URL as well with curl? – Brian Edwards Apr 12 '16 at 13:10
  • Yes, to get help on `curl` or anything else, use `man curl` to see the manual. Use `SPACE` to get next page and `q` to quit. Try typing `curl www.google.com` into Terminal. – Mark Setchell Apr 12 '16 at 13:11

1 Answers1

1

Try saving the following on your Desktop with filename MyScript:

#!/bin/bash

# Store the name of the file in a variable
file="/Volumes/SomeServer/SomeFile"

# Store website URL
website="http://SomeServer.com"

# Check if file exists
if [ -f "$file" ]; then
   echo File $file exists
   curl -L --silent "$website" | grep -q "YES"
   if [ $? -eq 0 ]; then
      echo Would delete file $file
      # rm "$file"
   fi
else
   echo File $file does not exist
fi

You will need to change the lines that start:

file="..."
website="..."

Then start Terminal using + space and start typing "Terminal" till it guesses you want the Terminal application. Then press Enter. That was called a "Spotlight search" and it is the way to find stuff on a Mac.

Now make the above script executable with the following, which you only need to do one time:

chmod +x $HOME/Desktop/MyScript

Now you can run it by typing:

$HOME/Desktop/MyScript

or double-clicking on the MyScript file on your Desktop.

At the moment, the script does NOT actually remove the file - I don't like removing other people's files. If it works how you expect, you can remove the # sign from the line like this and then it will actually remove the file:

# rm "$file"
Mark Setchell
  • 146,975
  • 21
  • 182
  • 306