Output Results from AppleScript

Discussion in 'Mac Programming' started by gpchess2k, Nov 29, 2016.

Tags:
  1. gpchess2k, Nov 29, 2016
    Last edited: Nov 29, 2016

    gpchess2k macrumors newbie

    gpchess2k

    Joined:
    Oct 12, 2015
    #1
    Hello,

    I am trying to output the results from my script for transparency reasons so the end user sees what has run successfully. I know im suppressing errors in my script but could I still output and if so could I output the commands that did go through without error? Below is a small portion of the script but I do want to add a 'Results' button to click on to open maybe a text file.

    Code:
    do shell script "security delete-certificate -c -t XXXXXXXXX.com > /dev/null 2>&1 &" with administrator privileges
    do shell script "security delete-certificate -c -t xxxxxxxxx.com > /dev/null 2>&1 &" with administrator privileges
    do shell script "while security delete-generic-password  -l Wired 802.1X >/dev/null
    do true; done" with administrator privileges
    do shell script "rm -rf ~/.Trash/*" with administrator privileges #Empties Trash Bin
    
    tell application "Finder"
        display dialog "Script has completed successfully!" buttons {"Restart", "Results", "Cancel"} default button "Cancel" with icon caution
        if button returned of result is "Restart" then
            tell application "Finder"
                restart
            end tell
        end if
    end tell
     
  2. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #2
    Hi,

    Slightly confused about what you're asking. Maybe you could try rephrasing your question, or making it more specific? e.g. "How do I write to a text file?". I expect that's why no-one's got back to you yet.
     
  3. gpchess2k thread starter macrumors newbie

    gpchess2k

    Joined:
    Oct 12, 2015
    #3
    Sure. How to output the results of the commands (do shell scripts) listed above in a text file.
     
  4. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #4
    OK.

    I don't fully understand the shell commands you're using. However, you're sending their output into /dev/null which is a big black hole from whence there is no return. If you redirect that output to a file instead then (if I understand correctly) you may be closer to your goal.

    For example:

    Code:
    do shell script "date > ~/Desktop/log.txt"
    That should send the output of the "date" command into a file called "log.txt" on the desktop of the currently logged in user.

    Hope that's of some help!
     
  5. MacUser2525 macrumors 68000

    MacUser2525

    Joined:
    Mar 17, 2007
    Location:
    Canada
    #5
    You do not it is useless for it a notification for it having run can be provided with an button to dismiss the notification on it. When I ran into this brick wall couple of days ago I went with the idea of the script re-directing its output to a .txt file then a open file.txt command at the end to open the resulting file created with the default app for text to get my output shown. Now that was Automator but I am pretty sure I seen nothing in them many, many hours of Googling to suggest Applescript could have accomplished what I wanted.
     
  6. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #6
    Not quite sure what you're saying there.

    It's definitely possible to capture the results of a "do shell script" in AppleScript. Or you can redirect output to a text file if you prefer. I'm not sure what you're saying can't be done in AppleScript?
     
  7. MacUser2525 macrumors 68000

    MacUser2525

    Joined:
    Mar 17, 2007
    Location:
    Canada
    #7
    I am saying you cannot get a dialog popping up to display the results of the process run, no trouble re-directing to a text file then opening the resulting text file with that output contained in it at the end of the script.
     
  8. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #8
    I get the feeling we're talking at crossed purposes here. Do you mean something like this?

    Code:
    set theResultOfTheScript to do shell script "ls -l ~ | head -n 5"
    display alert "Here are the results of the script" message theResultOfTheScript
    
     
  9. MacUser2525, Dec 1, 2016
    Last edited: Dec 1, 2016

    MacUser2525 macrumors 68000

    MacUser2525

    Joined:
    Mar 17, 2007
    Location:
    Canada
    #9
    Indeed we are all that damn time searching for a working example of it and here it is, Christ. Thanks.

    Edit: Display width of the dialog any way to set that?
     
  10. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #10
    Hi,

    With "display dialog" you don't have much control over the layout etc.

    If you want more control of the layout then you're looking at delving into Cocoa, which has a much steeper learning curve.
     
  11. MacUser2525, Dec 1, 2016
    Last edited: Dec 1, 2016

    MacUser2525 macrumors 68000

    MacUser2525

    Joined:
    Mar 17, 2007
    Location:
    Canada
    #11
    Yes I have learned that from this last bit of wasted time since I posted looking into it. Looks like Pashua or Platypus may be a possibility for what I need. Of course none of this would be necessary if the MediaInfo.app service it installed actually worked...

    Edit: Platypus for the win once I took the ten, fifth-teen minutes to figure it out.
     

Share This Page