I have an AppleScript Automator application that, when double-clicked, opens FTP and displays an alert confirming the same. It is working perfectly as expected. However, I am looking to make it a tad more intuitive so that it opens FTP ONLY if FTP isn't already open. If FTP is already open on my system, the app should close it.
So, basically I want to use the app as a toggle switch which opens or closes FTP depending on its prevailing status. The code I am currently using to open FTP and display the alert is as follows:
set ipaddr to IPv4 address of (get system info) set sun to short user name of (get system info) do shell script "sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist" with administrator privileges tell application "Finder" to display alert "FTP Launched and ready for file-transfer" & character id 8233 & character id 8233 & "User Name: " & sun & character id 8233 & "IP address: " & ipaddr
Can anyone please point me in the right direction? Is there any system variable that can be used to retrieve the FTP status? On Terminal, I could use this:
And the results would tell me if it's open or closed. But how can I let AppleScript know the same?
Additional info: Output of "ftp localhost" on Terminal
Here's the result of ftp localhost when FTP is closed:
And here's the result when FTP is open:
Here, I just hit return without any input and then it gives this: