Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Format AppleScript for Forum Post?

I know there were scripts that formatted AppleScript for good presentation in a previous incarnation of these forums.


Pasting a script into a reply seems to have the text flowing off the left side of the display box.


Does anyone have either (a) a tip to prevent this or (b) a script that will help presentation please?


Thanks.

Posted on Oct 15, 2014 4:16 PM

Reply
Question marked as Best reply

Posted on Oct 15, 2014 4:18 PM

Copy and paste it into a plain text field before posting it.


(114732)

10 replies

Oct 15, 2014 4:22 PM in response to Arkouda

When you open a new post, or reply, over in the upper right corner is the words, Use advanced editor. Click it.


Copy and paste your compiled AppleScript from the AppleScript editor directly into this window. Select all of the script, and then under Style in the toolbar, select Paragraph. This adjusts your AppleScript code so it is no longer truncated.


Of course, if there are really long lines, you may want to use the >> in the Toolbar, and pick one of the Syntax Highlighting languages to provide a horizontal scrollbar. I tend to pick Python, but plain, and others will work too.

Oct 15, 2014 6:37 PM in response to Arkouda

Something I discovered: If you look at copy/pasted applescript editor text in the forum, using the HTML option, you'll see text that looks like this:


<p style="text-indent: -41.6px;...


basically, the forum is adding a minus sign to the text-indent property so that the indentation goes in the wrong direction. So what I've taken to doing is:

  1. copy the applescript from the Applescript Editor into the forum text box
  2. switch to HTML mode
  3. copy the html into text wrangler (or some other text editor)
  4. search for '<p style="text-indent: -' and replace it with '<p style="text-indent: ' (deleting the spurious minus sign)
  5. copy the revised html back into the forum


When you do that, this:

tell application "System Events"


quit

end tell

becomes this:

tell application "System Events"


quit

end tell

works flawlessly.

Oct 21, 2014 5:10 PM in response to twtwtw

Twtwtw, you’re a genius! However, I prefer another workaround, which imho gives a better layout:


1. Copy the applescript from the AppleScript Editor into a new TextEdit document.

2. Replace every tab with a few ordinary spaces (6 is nice).

3. Save the TextEdit document as a Web Page (.html) on the Desktop.

4. Double click the html document to open it in Safari.

5. Copy the script from Safari.

6. Paste the script into the “Full Editor” text box.


When you do that, you obtain this:


tell application "System Events"

quit

end tell

Oct 22, 2014 12:01 AM in response to twtwtw

The only problem with that is if the values are too large (some of Apple's own scripts use text-indent: -39.3px and multiples of that for tabbing), which really spreads things out. So, unless you also change the values, you won't match what Script Editor shows. Also note that the line spacing is also spread out. I


This is from the Script Editor window:

User uploaded file

and this is with the minus sign removed:


repeat with i from 1 to number of items in the item_list

set this_item to itemi of the item_list

set this_item to (source_folder & this_item) as alias

set this_info to info forthis_item

set the current_name to the name of this_info

if folder of this_info is false and ¬

alias of this_info is false then

if the button_pressed is "Prefix" then

set the new_file_name to the (the prefix_or_suffix & the current_name) as string

else

set the new_file_name to the (the current_name & the prefix_or_suffix) as string

end if

my set_item_name(this_item, the new_file_name)

end if

end repeat

27" i7 iMac (Mid 2011) refurb, OS X Yo (10.10), Mavs, ML & SL, G4 450 MP w/10.5 & 9.2.2

Oct 22, 2014 7:39 AM in response to baltwo

And this is with my workaround:


repeat with i from 1 to number of items in the item_list

set this_item to item i of the item_list

set this_item to (source_folder & this_item) as alias

set this_info to info forthis_item

set the current_name to the name of this_info

if folder of this_info is false and ¬

alias of this_info is false then

if the button_pressed is "Prefix" then

set the new_file_name to the (the prefix_or_suffix & the current_name) as string

else

set the new_file_name to the (the current_name & the prefix_or_suffix) as string

end if

my set_item_name(this_item, the new_file_name)

end if

end repeat

Jan 26, 2015 12:51 PM in response to Arkouda

Hi All,


Hiroto, here, has the simplest suggestion I have seen.

Uncheck this in applescript editor preferences:

User uploaded file

copy and paste and you get this:


activateapplication "Safari"

tell application "Safari"

tell application "System Events" to keystroke "v" using command down

end tell

My only complaint is that I have to unbold the rest of my comments.

quinn

Format AppleScript for Forum Post?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.