1

Say I want to print "hello world" NOT "hello world\n". How do I do this in Apple Script?

It appears log cannot do this. Presumably write could, except I can't figure out how to get standard output's file descriptor.

Joshua Cheek
  • 30,436
  • 16
  • 74
  • 83
  • Where do you want to write ? in a Terminal Window ? in a text file ? on an opened document (which application) ? – pbell Oct 07 '16 at 17:11
  • Standard output and eventually another program's standard input as well (which is presumably a pipe). – Joshua Cheek Oct 08 '16 at 21:59
  • Does this answer your question? [How to log objects to a console with AppleScript](https://stackoverflow.com/questions/13653358/how-to-log-objects-to-a-console-with-applescript) – Wolfgang Fahl Nov 21 '20 at 13:42

1 Answers1

0

I think instruction 'keystroke' from "System Events' should do what you want. It simulate entries via keyboard. In order to simulate that entry in an other program, you must first make this other program in front (with activate)

the script bellow makes Word up front and then types the sentence, without \n in the document, where the cursor is.

tell application "Microsoft Word" to activate
tell application "System Events"    to keystroke "this is my text without return"

You can also use 'keystroke' with options like 'using command down'. For instance, the following script simulate a 'command n' in Word which is the short cut for menu new document :

tell application "Microsoft Word" to activate
tell application "System Events" to keystroke "n" using command down
pbell
  • 2,965
  • 1
  • 16
  • 13
  • Can I tell my current script to keystroke? I need to print to stdout, which is associated with my current program. ie the `log` command would do it, but it appends a trailing newline. The `write` command would do it, but I can't figure out how to get it to work with stdout. – Joshua Cheek Oct 09 '16 at 07:59