Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gpchess2k

macrumors member
Original poster
Oct 12, 2015
42
0
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
 
Last edited:

superscape

macrumors 6502a
Feb 12, 2008
937
223
East Riding of Yorkshire, UK
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.
 

gpchess2k

macrumors member
Original poster
Oct 12, 2015
42
0
Sure. How to output the results of the commands (do shell scripts) listed above in a text file.
 

superscape

macrumors 6502a
Feb 12, 2008
937
223
East Riding of Yorkshire, UK
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!
 

MacUser2525

Suspended
Mar 17, 2007
2,097
377
Canada
Sure. How to output the results of the commands (do shell scripts) listed above in a text file.

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.
 

superscape

macrumors 6502a
Feb 12, 2008
937
223
East Riding of Yorkshire, UK
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.

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?
 

MacUser2525

Suspended
Mar 17, 2007
2,097
377
Canada
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?

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.
 

superscape

macrumors 6502a
Feb 12, 2008
937
223
East Riding of Yorkshire, UK
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
 
  • Like
Reactions: MacUser2525

MacUser2525

Suspended
Mar 17, 2007
2,097
377
Canada
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

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?
 
Last edited:

MacUser2525

Suspended
Mar 17, 2007
2,097
377
Canada
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.

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.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.