Monday, December 9, 2019

#1 2019-03-08 01:42:26 pm

Titanium
Member
From:: ~/Desktop
Registered: 2005-08-22
Posts: 61
Website

Simulate the Enter key

Hello,

I want run the following command:

sudo sysdiagnose -v

From the Terminal, it's necessary to press Enter.

In do shell script a message appears:
Triggering sysdiagnose programmatically from CLI with incorrect arguments. Exiting.

Is it possible to simulate the Enter key to run this command in do shell script ?

do shell script "sysdiagnose -v" with administrator privileges

Thanks.


iMac 27" 3,4 Ghz - MacOS  Catalina
https://www.titanium-software.fr

Offline

 

#2 2019-03-13 08:29:19 am

FredrikM
Member
From:: Förslöv, Sweden
Registered: 2019-02-19
Posts: 21

Re: Simulate the Enter key

If you don't mind that the terminal window is showing you could use something like this.

Applescript:


tell application "Terminal"
   activate
   set scriptOne to "sudo sysdiagnose -v"
   set scriptTwo to "-my password-"
   tell application "System Events" to keystroke scriptOne & return
   delay 1
   tell application "System Events" to keystroke scriptTwo & return
   delay 1
   tell application "System Events" to keystroke return
end tell

Offline

 

#3 2019-11-26 09:51:23 pm

Shahab
Member
Registered: 2019-11-26
Posts: 1

Re: Simulate the Enter key

Hi Titanium,

Did you figure out the solution. Im also in the same situation.


Titanium wrote:

Hello,

I want run the following command:

sudo sysdiagnose -v

From the Terminal, it's necessary to press Enter.

In do shell script a message appears:
Triggering sysdiagnose programmatically from CLI with incorrect arguments. Exiting.

Is it possible to simulate the Enter key to run this command in do shell script ?

do shell script "sysdiagnose -v" with administrator privileges

Thanks.

Offline

 

#4 2019-11-27 02:33:49 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 768

Re: Simulate the Enter key

Shahab wrote:

Hi Titanium,

Did you figure out the solution. Im also in the same situation.


Well, as I understand from technical notes of Apple:
You can script Terminal and send a series of commands to the same window, but you can't control an interactive tool like sysdiagnose with do shell script (that is, in the background).

Applescript:


tell application "Terminal" to do script "sudo sysdiagnose -v -f ~/Desktop"

This triggers sysdiagnose, but shell waits for user input (for password).
After entering the password, shell waits for user input again (for confirming to start diagnostics).
Here, with 2 rest steps, you can't avoid GUI scripting. So, all code should be like this:

Applescript:


tell application "Terminal" to do script "sudo sysdiagnose -v -f ~/Desktop"
delay 1

tell application "System Events"
   set frontmost of process "Terminal" to true
   keystroke "YourPassword" & return
   delay 1
   keystroke return
end tell

Last edited by KniazidisR (2019-11-27 03:45:18 am)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#5 2019-11-27 09:44:27 am

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 464

Re: Simulate the Enter key

If you want to avoid username and password entry for a particular command run under a particular user, you can add it to your /etc/sudoers file.

There are potential security implications, but if this is a personal computer I'd expect it's fine, and sysdiagnose probably has low potential for abuse anyway.

https://www.tecmint.com/run-shell-scrip … -in-linux/


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Online

 

#6 2019-11-27 10:29:57 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 768

Re: Simulate the Enter key

For more security you can use the following script. Save it as run-only script or, better, as applet.

Applescript:


set aPassword to text returned of ¬
   (display dialog "Please, enter your password" default answer "" with hidden answer)

tell application "Terminal" to do script "sudo sysdiagnose -v -f ~/Desktop"
delay 2

tell application "System Events"
   set frontmost of process "Terminal" to true
   keystroke aPassword & return
   delay 2
   keystroke return
end tell

Last edited by KniazidisR (2019-11-27 10:31:32 pm)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#7 2019-11-28 01:25:44 pm

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 464

Re: Simulate the Enter key

If you're going to ask for a password each time it's run, you might as well skip the terminal scripting.

Applescript:

set aPassword to text returned of (display dialog "Please, enter your password" default answer "" with hidden answer)

do shell script "echo " & aPassword & " | sudo -S sysdiagnose -v -f ~/Desktop"

But I wouldn't call that a "more security" option than adding sysdiagnose to sudoers.

It's not hard to extract a plain text password from a run-only AppleScript.

I exported KniazidisR's script as a run-only Applescript application, as suggested. Only change was I changed the shell command to "sudo ls ~/Desktop" because I didn't need a sysdiagnose.

I ran it once, and entered the (incorrect) password "bonkers"

Then inside the Application bundle, I opened /Pwd Test Run-Only.app/Contents/Resources/Scripts/main.scpt in TextEdit, which yields:

FasdUAS 1.101.10ˇˇˇ˛ˇˇˇ˛ˇ˝ˇ˝ˇ¸ˇ˚
ˇ¸.aevtoappnullÄê****ˇ˚0    apassword    aPasswordˇ˙ˇ˘ˇ¯ˇ˜ˇˆ
ˇ˙.aevtoappnullÄê****ˇ˘ˇ¯ˇ˜ˇı    ˇÙˇÛˇÚˇÒˇ
ˇÔˇÓˇÌ
ˇÏˇÎˇÍ±6Please, enter your password
ˇı
dtxt    ±
ˇÙ
htxtˇÛ
ˇÚ.sysodlogaskrTEXT
ˇÒ
ttxtˇ0    apassword    aPassword
Œ@alisp
Faster Planet‘ÍDLH+¨'Terminal.appÌΩ‘+√ˇˇˇˇ         Utilities‘Íäú‘+=¨'D3Faster Planet:Applications:Utilities:Terminal.appTerminal.app
Faster Planet#Applications/Utilities/Terminal.app/ˇˇ±"sudo ls ~/Desktop
ˇÔ.coredoscnullˇˇÄˇˇÄctxt
ˇÓ.sysodelanullˇˇÄˇˇÄnmbrÚsevsalisî
Faster Planet‘ÍDLH+%System Events.app˝ì”¬Íˡˇˇˇ     CoreServices‘Íäú”√#(%$#>Faster Planet:System:Library:CoreServices:System Events.app$System Events.app
Faster Planet-System/Library/CoreServices/System Events.app/ˇˇ
ˇÌ
prcs
±Terminal
ˇÏ
pisf
ˇÎ
ret
ˇÍ.prcskprsnullˇˇÄctxtˇˆE‡·‚„e‰Ê,E◊OËÈj
UOljOÏ"e*ÌÓ/Ô,FO«_%jOljO_jU±bonkersascr˙fifi≠



And as you'll note, I bolded the password there in plain text.

Applescript saves the contents of top-level variables into the script... and if it's a string, it saves it as plain text, which is easily accessible even on a run-only script.

So your suggested security improvement would leave the admin password hanging around in plain text on the computer.

You can avoid having the script save the password by never setting a variable to it:

Applescript:


do shell script "echo " & text returned of (display dialog "Please, enter your password" default answer "" with hidden answer) & " | sudo -S sysdiagnose -v -f ~/Desktop"

I tested that, and the password is not saved in the script.

If you had a longer script, not being able to save something as a variable might get annoying. You can also stop it from saving the variable contents back to the script by putting it into a handler outside the "run" (or default) handler.

Applescript:

shell_sysdiagnose()

on shell_sysdiagnose()
   set aPassword to the text returned of (display dialog "Please, enter your password" default answer "" with hidden answer)
   do shell script "echo " & aPassword & " | sudo -S sysdiagnose -v -f ~/Desktop"
end shell_sysdiagnose

Depending on what an acceptable level of security is on the system in question, if you need it to run without asking for a password each time, and you don't want to add sysdiagnose to sudoers, you can obfuscate the password in a run-only script. It would certainly be possible to reconstruct the password out of this... but it would take some really serious effort, so personally, I'd only be worried about it in the most dire security situations.

There are various ways, but I'll just grab DJ Bazzie Wazzie's from here:
https://stackoverflow.com/questions/146 … ipt-script

Run this script with your password:

Applescript:

set encPass to simpleEncryption("bonkers")
return encPass

on simpleEncryption(_str)
   set x to id of _str
   repeat with c in x
       set contents of c to c + 100
   end repeat
   return string id x
end simpleEncryption

Take what it returns and plug it in for "encPass" here:

Applescript:

shell_sysdiagnose()

on shell_sysdiagnose()
   set encPass to ""
   set aPassword to simpleDecryption(encPass)
   do shell script "echo " & aPassword & " | sudo -S sysdiagnose -v -f ~/Desktop"
end shell_sysdiagnose

on simpleDecryption(_str)
   set x to id of _str
   repeat with c in x
       set contents of c to c - 100
   end repeat
   return string id x
end simpleDecryption

Then save that script as run-only. The password will technically be extractable from the script, but it would take some effort to get it back out. Here's the extractable plain text:

FasdUAS 1.101.10ˇˇˇ˛ˇˇˇ˛ˇ˝ˇ˝ˇ¸ˇ˚ˇ˙ˇ¸0shell_sysdiagnoseˇ˚$0simpledecryptionsimpleDecryption
ˇ˙.aevtoappnullÄê****ˇ˘ˇ¯ˇ˜ˇˆˇıˇ˘0shell_sysdiagnoseˇ¯ˇ˜ˇˆˇÙˇÛˇÙ0encpassencPassˇÛ0    apassword    aPassword    ˇÚ
ˇÒ    ±∆”“œ…÷◊ˇÚ$0simpledecryptionsimpleDecryption
±


echo ±0 |  sudo -S ls ~/Desktop
ˇÒ.sysoexecTEXTˇˇÄTEXTˇı‡E∞O*†k+E±O‚°%„%jˇˇÔˇÓˇÌˇÏˇ$0simpledecryptionsimpleDecryptionˇÔˇÓˇÎˇÎˇÍˇÍ0_strˇÌˇÈˇËˇÁˇÈ0_strˇË0xˇÁ0cˇÊˇÂˇ‰ˇ„ˇ‚ˇ·ˇ‡ˇfl
ˇÊ
ID 
ˇÂ
kocl
ˇ‰
cobj
ˇ„.corecnte********ˇ‚d
ˇ·
pcnt
ˇ‡
TEXT
ˇflkfrmID  ˇÏ+†‡,E±O°[·‚lkh¢‰¢Â,F[OYˇÛO*Ê°Á0Eˇfiˇ›ˇ‹ˇ€ˇ⁄
ˇfi.aevtoappnullÄê****ˇ›ˇ‹ˇ€ˇŸˇŸ0shell_sysdiagnoseˇ⁄*j+ascr˙fifi≠



There are Applescripts with more advanced encryption you can Google up:
https://www.macscripter.net/viewtopic.php?id=19520
but if you actually need that in your situation, you might want to just reconsider the whole security case for what you're doing.


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Online

 

#8 2019-11-29 12:36:50 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 768

Re: Simulate the Enter key

Yes that's right. Saving the script as run-only is a child’s defense. So, it is better saving it as applet.

I would only add that 100 percent protection does not exist. In 1993, I bet with one representative of a very serious software company in my country. He told me that no one has managed to break their passwords. Then I asked him for a protected copy of one expensive program ($ 1400).

 I went home and ran the DEBUG command with this program (on my old Windows computer). This command provides everything in Assembler language - in machine codes. I delved into this code for 3 days and found the password request point in the code. Then I inserted a JUMP instruction at this point to bypass the code verification fragment. On the 4th day, I took the hacked copy to the owner and earned $ 500. He was surprised and asked me how I managed to find a password ?! It consists of 128 characters! I said: "I still don’t know your password. I just bypassed it ..."

t.spoon wrote:

You can avoid having the script save the password by never setting a variable to it:

Applescript:


do shell script "echo " & text returned of (display dialog "Please, enter your password" default answer "" with hidden answer) & " | sudo -S sysdiagnose -v -f ~/Desktop"

I tested that, and the password is not saved in the script.


I tested it, and that code doesn't work at all. Applescript execution error: "Password:Triggering sysdiagnose programmatically from CLI with incorrect arguments. Exiting."

t.spoon wrote:

Applescript:


shell_sysdiagnose()

on shell_sysdiagnose()
   set aPassword to the text returned of (display dialog "Please, enter your password" default answer "" with hidden answer)
   do shell script "echo " & aPassword & " | sudo -S sysdiagnose -v -f ~/Desktop"
end shell_sysdiagnose

I tested that, and the password is not saved in the script.


I tested that too, and that code doesn't work at all too. The same execution error occurs.

As I already said above, you can't avoid GUI scripting Terminal.app for interactive shell commands. I will repeat my code in a slightly modified form. It works without errors and is quite safe as an application:

Applescript:


tell application "Terminal" to do script "sudo sysdiagnose -v -f ~/Desktop"
set aPassword to display dialog "Please, enter your password" default answer "" with hidden answer

tell application "System Events"
   set frontmost of process "Terminal" to true
   keystroke (text returned of aPassword) & return
   delay 1
   keystroke return
end tell

NOTE: I don't see any way to avoid setting the password to variable, as we need the Terminal process as frontmost.

Last edited by KniazidisR (2019-11-29 06:25:25 am)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#9 2019-11-29 09:37:22 am

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 464

Re: Simulate the Enter key

KniazidisR,

Regarding "Applets"

Can you explain what you mean by an "Applet?" I was saving as a run-only application. From Script Editor, "Export" -> File Format: Application with "Run Only" selected.

Or from Script Debugger, "Export Run-Only Script" Format: Application.

I had thought that's what you meant by an "Applet," it's how I see it being used elsewhere:

https://www.macosxautomation.com/apples … index.html

As I stated, I "exported KniazidisR's script as a run-only Applescript application" and the location where I found the plain-text password was "inside the Application bundle" in "/Pwd Test Run-Only.app/Contents/Resources/Scripts/main.scpt "

So I don't understand what you're referring to by an "Applet" if not an Applescript run-only application. Please let us know.

Regarding your error message

The reason the code doesn't work is because I copied and pasted it from your script without testing it, and yours doesn't work either.

Sorry, I should have tested rather than assuming prior contributors had posted working code. That was definitely a mistake.

As I noted, in my testing, I switched out the "sysdiagnose" command for an "ls" because I didn't really want to run a bunch of sysdiagnoses, and the point of the script is to work around the requirement of entering a password for sudo, so the commands provided to sudo are irrelevant here. Well, irrelevant as long as they're functional.

Running your script:

Applescript:



set aPassword to text returned of ¬
   (display dialog "Please, enter your password" default answer "" with hidden answer)

tell application "Terminal" to do script "sudo sysdiagnose -v -f ~/Desktop"
delay 2

tell application "System Events"
   set frontmost of process "Terminal" to true
   keystroke aPassword & return
   delay 2
   keystroke return
end tell

Yields a terminal window with the following contents:

Toms-Hackintosh:~ tspoon$ sudo sysdiagnose -v -f ~/Desktop
Password:
Unexpected option or insufficient arguments.

sysdiagnose version: 3.0 (203.500000)
USAGE: sysdiagnose [-h] [-f results_directory] [-A archive_name] [-q] [-b] [-p] [-d] [-X] [process_name | pid]
          -h                      Display this help
          -f results_directory    Specify the directory where results will be stored
          -A archive_name         Specify the name of the archive created in the results directory
          -q                      Skip footprint
          -b                      Do not show a Finder window upon completion
          -p                      Request only time-sensitive data to be collected (performance issues)
          -d                      Request only log data to be collected (historical issues)
          -X                      Run all diagnostics with no timeout
          [process_name | pid]    If a single process appears to be slowing down the system,
                                  passing in the process name or ID as the argument gathers
                                  addition process-specific diagnostic data

DESCRIPTION:
  sysdiagnose gathers system diagnostic information helpful in investigating system performance issues.
  A great deal of information is harvested, spanning system state and configuration. The data is stored /var/tmp directory.
  sysdiagnose is automatically triggered when the following key chord is pressed: Control-Option-Command-Shift-Period.
WHAT sysdiagnose COLLECTS:
  - A spindump of the system
  - Several seconds of fs_usage ouput
  - Several seconds of top output
  - Data about kernel zones
  - Status of loaded kernel extensions
  - Resident memory usage of user processes
  - Recent system logs
  - A System Profiler report
  - Recent crash reports
  - Disk usage information
  - I/O Kit registry information
  - Network status
  - If a specific process is supplied as an argument: a list of malloc-allocated buffers in the process's heap is collected
  - If a specific process is supplied as an argument: data about unreferenced malloc buffers in the process's memory is collected
  - If a specific process is supplied as an argument: data about the virtual memory regions allocated in the process
Toms-Hackintosh:~ tspoon$



So I went back to the first message... which says they want to run "sudo sysdiagnose -v." Running that in my terminal, it just says that "-v" is an invalid argument for sysdiagnose, and sure enough, -v is not in the man page for sysdiagnose either.

Shahab's recent post kicking off this discussion also says the error he was getting is "Triggering sysdiagnose programmatically from CLI with incorrect arguments. Exiting."

Which isn't surprising since we've all been calling sysdiagnose with incorrect arguments in our code.

If you try any of my scripts with the invalid "-v" argument removed, and just stick to valid shell commands, they work.

Last edited by t.spoon (2019-11-29 09:59:14 am)


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Online

 

#10 2019-11-29 02:09:13 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 768

Re: Simulate the Enter key

t.spoon wrote:

If you try any of my scripts with the invalid "-v" argument removed, and just stick to valid shell commands, they work.


The "-v" argument is valid. You can see the options if you run sudo sysdiagnose -h in the Terminal:
-v                      Enable verbose mode to display the container information as it executes.

But I tried your scripts with removed -v option. They still throws the same error and doesn't work. So, you still should test your suggestions before posting here, since the Apple is right here and not you.

Regarding the applet: AppleScript has applets and droplets. Applet is small application.

Last edited by KniazidisR (2019-11-29 02:13:33 pm)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#11 2019-11-29 07:56:20 pm

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 464

Re: Simulate the Enter key

The presence of -v must be an environmental difference. It's not valid on my system running 10.12.5. I mean, obviously, I pasted in the full returned text showing that the error returned with running "sudo sysdiagnose -v -f ~/Desktop" was "Unexpected option or insufficient arguments." And the -f option is valid. I also said that simply running "sudo sysdiagnose -v" from Terminal on my computer just yields an error, so obviously it's not valid on my system.

Your suggestion of "sudo sysdiagnose -h" also shows it's not present on my system... "sudo sysdiagnose -h" doesn't show it, but of course it wouldn't since I already said it wasn't in the man page on my system.

Toms-Hackintosh:~ tspoon$ sudo sysdiagnose -h
Password:
sysdiagnose version: 3.0 (203.500000)
USAGE: sysdiagnose [-h] [-f results_directory] [-A archive_name] [-q] [-b] [-p] [-d] [-X] [process_name | pid]
          -h                      Display this help
          -f results_directory    Specify the directory where results will be stored
          -A archive_name         Specify the name of the archive created in the results directory
          -q                      Skip footprint
          -b                      Do not show a Finder window upon completion
          -p                      Request only time-sensitive data to be collected (performance issues)
          -d                      Request only log data to be collected (historical issues)
          -X                      Run all diagnostics with no timeout
          [process_name | pid]    If a single process appears to be slowing down the system,
                                  passing in the process name or ID as the argument gathers
                                  addition process-specific diagnostic data

DESCRIPTION:
  sysdiagnose gathers system diagnostic information helpful in investigating system performance issues.
  A great deal of information is harvested, spanning system state and configuration. The data is stored /var/tmp directory.
  sysdiagnose is automatically triggered when the following key chord is pressed: Control-Option-Command-Shift-Period.
WHAT sysdiagnose COLLECTS:
  - A spindump of the system
  - Several seconds of fs_usage ouput
  - Several seconds of top output
  - Data about kernel zones
  - Status of loaded kernel extensions
  - Resident memory usage of user processes
  - Recent system logs
  - A System Profiler report
  - Recent crash reports
  - Disk usage information
  - I/O Kit registry information
  - Network status
  - If a specific process is supplied as an argument: a list of malloc-allocated buffers in the process's heap is collected
  - If a specific process is supplied as an argument: data about unreferenced malloc buffers in the process's memory is collected
  - If a specific process is supplied as an argument: data about the virtual memory regions allocated in the process
Toms-Hackintosh:~ tspoon$



As for the scripts not working... that's a pretty odd environmental difference to stop them from working without the -v on your computer (or with it, if "-v" is valid on your system).
I mean, you pasted the error you got into your message:

Applescript execution error: "Password:Triggering sysdiagnose programmatically from CLI with incorrect arguments. Exiting."


And that's pretty weird that you're getting the error "Triggering sysdiagnose programmatically from CLI with incorrect arguments" if you're passing sysdiagnose correct arguments.

I did try all three of my scripts on my system without the -v, and they all ran fine. No errors from Applescript. The Sysdiagnose logs were all saved to the desktop correctly. The usual terminal output was returned to Applescript after the command completed for each.

Just in case there's anyone else following along here, can anyone else reproduce KniazidisR's error with any of my scripts, if you remove the -v argument? I'm quite curious what could possibly cause terminal to error that the command had incorrect arguments supplied if it doesn't.

I'm still not clear on if there's something different about what you're referring to as an "Applet" compared to my example of saving the script as a run-only application, which was the example I gave where it saves the admin password in plain if used with your script.


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Online

 

#12 2019-11-29 08:23:11 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6065

Re: Simulate the Enter key

Tom,

I haven't followed this, but sysdiagnose does seem to have changed a bit. Here's what I see in 10.15.1:

iMac-shane:~ shane$ sudo sysdiagnose -h
sysdiagnose version: 3.0 (787.410000)
USAGE: sysdiagnose [-h] [-f results_directory] [-A archive_name] [-q] [-b] [-p] [-d] [-X] [process_name | pid]
          -h                      Display this help.
          -v                      Enable verbose mode to display the container information as it executes.
          -f results_directory    Specify the directory where results will be stored.
          -A archive_name         Specify the name of the archive created in the results directory.
          -V volume_path          Specify the root volume for sysdiagnose to run on.
          -n                      Do not tar the resulting sysdiagnose directory.
          -k                      Do not remove the temporary directory.
          -F                      Get feedback data.
          -S                      Disable streaming to tarball.
          -u                      Disable UI feedback.
          -Q                      Skip footprint.
          -b                      Do not show a Finder window upon completion.
          -p                      Collect only time-sensitive data; disregards previous -d or -r flags.
          -P                      Do not collect time-sensitive data.
          -g                      Collect only log Generation data; disregards previous -p or -r flags.
          -G                      Do not run log generation data.
          -d                      Collect only log data; disregards previous -p or -r flags.
          -D                      Do not collect log data.
          -r                      Collect only log archive; disregards previous -p or -d flags.
          -R                      Do not collect log archive.
          [process_name | pid]    If a single process appears to be slowing down the system,
                                  passing in the process name or ID as the argument gathers
                                  additional process-specific diagnostic data; Specify only ONE process
                                  at a time -- specifying multiple processes is not supported.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#13 2019-12-01 05:02:58 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 768

Re: Simulate the Enter key

t.spoon wrote:

I'm still not clear on if there's something different about what you're referring to as an "Applet" compared to my example of saving the script as a run-only application, which was the example I gave where it saves the admin password in plain if used with your script.


Hi, t.spoon. It seems, sysdiagnose has changed, so your snippets which works fine on your old system, doesn't work on my Mojave operation system. I guess, it doesn't work on Catalina too. You are absolutely right about one thing, and I was wrong: for better security you need to use the code as a handler so that AppleScript cannot save the password (as value of top-level variable) in the application's bundle:

Applescript:


shell_SystemDiagnose() of me

on shell_SystemDiagnose()
   tell application "Terminal" to do script "sudo sysdiagnose -v -f ~/Desktop"
   set aPassword to display dialog "Please, enter your password" default answer "" with hidden answer
   tell application "System Events"
       set frontmost of process "Terminal" to true
       keystroke (text returned of aPassword) & return
       delay 1
       keystroke return
   end tell
end shell_SystemDiagnose

NOTE: I guess, other way is setting variable aPassword to "" (or, to whatever other then the user password) immediately after keystroke code line.

Last edited by KniazidisR (2019-12-01 05:21:23 am)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#14 2019-12-04 03:17:22 pm

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 464

Re: Simulate the Enter key

KniazidisR,

Thanks for clarifying the stored variable issue with Applescript Applications.

I got a chance to access a computer on Catalina 10.15.1.

So, with the updates to sysdiagnose with newer versions, it now needs the -u argument provided when it's being run programmatically. The older version of sysdiagnose on my system didn't have "-u" and could be run "headless" without any special arguments.

So this works on newer versions of MacOS, and returns the "verbose" information requested with the "-v" flag to Applescript.

Applescript:

set sysdiagnoseResult to do shell script "echo " & text returned of (display dialog "Please, enter your password" default answer "" with hidden answer) & " | sudo -S sysdiagnose -u -v -f ~/Desktop"

Although I'm probably missing the boat here with doing this outside a terminal window; the intention of running it with the "-v" argument is probably because the original asker was looking for live feedback as it executes.

Posting because it might be handy to someone in the future if they want to run sysdiagnose programmatically. I'm guessing in some cases where someone wants to script sysdiagnose, they would NOT want the terminal to pop up.


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Online

 

#15 2019-12-04 11:09:49 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 768

Re: Simulate the Enter key

t.spoon wrote:

Although I'm probably missing the boat here with doing this outside a terminal window; the intention of running it with the "-v" argument is probably because the original asker was looking for live feedback as it executes.

Posting because it might be handy to someone in the future if they want to run sysdiagnose programmatically. I'm guessing in some cases where someone wants to script sysdiagnose, they would NOT want the terminal to pop up.


Well, t.spoon, thank you very much. Your last code runs perfect, and goes to my scripts library as one of the useful scripts, along with my own script (which shows the process live). I just will remove the -v option from your script.

Last edited by KniazidisR (2019-12-04 11:12:45 pm)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)