Skip to content

Instantly share code, notes, and snippets.

@pandurang90
Last active January 3, 2016 23:58
Show Gist options
  • Save pandurang90/8538105 to your computer and use it in GitHub Desktop.
Save pandurang90/8538105 to your computer and use it in GitHub Desktop.
applescript to transfer file using netcat
tell application "SystemUIServer"
set actionSelected to the button returned of (display dialog "What you want to do?" buttons {"Send file", "Receive file"} default button 2)
if actionSelected = "Send file" then
set filepath to POSIX path of (choose file)
display dialog "Please enter IP address of receiver:" default answer ""
set ipAddress to text returned of result
if ipAddress = "" then
repeat
display dialog "IP address cant be blank,Please enter IP address of receiver:" default answer ""
set ipAddress to text returned of result
if ipAddress is not equal to "" then exit repeat
end repeat
end if
else
display dialog "Please enter a file name with extension:" default answer ""
set filename to text returned of result
if filename = "" then
repeat
display dialog "Filename cant be blank,Please enter a file name with extension:" default answer ""
set filename to text returned of result
if filename is not equal to "" then exit repeat
end repeat
end if
end if
display dialog "Please enter a port number ,must be integer:" default answer ""
set portnumber to text returned of result
if portnumber = "" then
repeat
display dialog "Port number cant be blank, Please enter a port number, must be integer:" default answer ""
set portnumber to text returned of result
if portnumber is not equal to "" then exit repeat
end repeat
end if
if actionSelected = "Send file" then
display dialog "Sending"
do shell script "nc " & ipAddress & " " & portnumber & " < " & filepath & " -"
"sending"
else
display dialog "Receiving"
do shell script "nc -l " & portnumber & " > " & filename
"receiving"
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment