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

Update to Format a link and an Applescipt for posting

I have an update to the script in Format a link and an Applescipt for posting.
http://discussions.apple.com/thread.jspa?threadID=2223315&tstart=0

Found a bug in my applescript program. The most series one is that I left out the escape character which is the backslash ( \ ) .The changes are prefixed by the data, Nov 7, 2009.

The code will be in my second post.

I included a copy of the test case for alter clipboard, my applescript program.
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
font-weight: normal;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 600px; height: 300px;
color: #000000;
background-color: #FFEE80;
overflow: auto;"
title="">1234567890123456789012345678901234567890
|
|
|
|
|
|
|
|
|
|
|
||
| |
| |
| |
| |
| |
1234567890123456789012345678901234567890
,
.
/
<
>
?
;
'
:
"
'
[
]
\
{
}
|
`
-
=
~
!
@
#
$
%
^
&
*
(
)
_
+
,,
..
//
<<
>>
??
;;
''
::
""
''
[[
]]
\\
{{
}}
||
``
--
==
~~
!!
@@
##
$$
%%
^^
&&
**
((
))
__
++
,,,
...
///
<<<
>>>
???
;;;
'''
:::
"""
'''
[[[
]]]
\\\
{{{
}}}
|||
```
---
===
~~~
!!!
@@@
###
$$$
%%%
^^^
&&&
***
(((
)))
___
+++
,,,,....////<<<<>>>>????;;;;''''::::""""''''[[[[]]]]\\\\{{{{}}}}||||````----==== ~~~~!!!!@@@@####$$$$%%%%^^^^&&&&****(((())))____++++
,abc,.abc./abc/<abc<>abc>?abc?;abc;'abc':abc:"abc"'abc'[abc[]abc]\abc\{abc{}abc} |abc|`abc`-abc-=abc=~abc~!abc!@abc@#abc#$abc$%abc%^abc^&abc&*abc*(abc()abc)_abc_ +abc+
,,abc,,..abc..//abc//<<abc<<>>abc>>??abc??;;abc;;''abc''::abc::""abc""''abc''[[a bc[[]]abc]]\\abc\\{{abc{{}}abc}}||abc||``abc``--abc--==abc==~~abc~~!!abc!!@@abc@ @##abc##$$abc$$%%abc%%^^abc^^&&abc&&**abc**((abc(())abc))__abc__++abc++
1234567890123456789012345678901234567890
Printable characters. These are set to blank:
127 -- control character
202 -- nonbreaking space. becomes a space.
1234567890123456789012345678901234567890
!"#$%&'()*+,-./
0123456789:;<=>?
@ABCDEFGHIJKLMNO
PQRSTUVWXYZ[\]^_
`abcdefghijklmno
pqrstuvwxyz{|}~
ÄÅÇÉÑÖÜáàâäãåçéè
êëíìîïñóòôöõúùûü
†°¢£§•¶ß®©™´¨≠ÆØ
∞±≤≥¥µ∂∑∏π∫ªºΩæø
¿¡¬√ƒ≈∆«»… ÀÃÕŒœ
–—“”‘’÷◊ÿŸ⁄€‹›fifl
‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔ
ÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ
1234567890123456789012345678901234567890
Try trailing spaces.
|
|
| |
| |
| |

|
|
| |
| |
| |




|
|
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890123456789012345678901234567890
Notes:
• Muliple returns necessitate a blank being inserted in the lines.
• Tabs get changed to blanks
• ASCI 202 -- nonbreaking space. becomes a space.
• The last return gets deleted.
differences begin here:



1234567890123456789012345678901234567890
<<<
<<<
<<<
1234567890123456789012345678901234567890
asci 202 nonbreaking space

The end.


</pre>

iMac G3 600, Mac OS X (10.4.11)

Posted on Nov 11, 2009 12:19 PM

Reply
1 reply

Nov 11, 2009 12:21 PM in response to rccharles

(*
Name: alter-clipboard

Input: Clipboard

Output: Clipboard

This AppleScript program is designed to convert a forum-reply web address to a link to a forum post, to convert special characters to their HTML symbols, and to convert programming language code to a form that does not get mangled.

1) When you wish to reference another Apple discussion forum post, I found the process convoluted. The Apple form software does not provide for the display of a form post link. Instead, you must construct the link from a reply post. This AppleScript simplifies the process.

When the clipboard contains a link to a forum reply page, do the conversion.

Here is that way:
a) Find the particular post you wish to reference.
b) Click on the reply icon.
c) Copy the Web address to the clipboard (command+c).
d) Run this AppleScript to convert the Web address.
e) Paste (command+v) the converted Web address into your post.

For example, you:
• Want to reference a post on how to improve the performance of Tiger. You find a post by Texas Mac Man with a list of possibilities.
• Click on the Reply option and highlight the Web address because you know the address contains a reference to this post.
• Type command+c to copy the address to the clipboard. The clipboard now contains:
http://discussions.apple.com/post&#033;reply.jspa?messageID=9124252
• Run this AppleScript to convert the Web address. The clipboard now contains:
http://discussions.apple.com/message.jspa?messageID=9124252&#035;9124252
• Type command+v to paste the address into your new post.

2) Assume that the clipboard contains special symbols or formated programming language code to convert.

The simpleFormatting property switch in the code selects teletype text ( tt ) when true and selets preformated text ( pre ) when false.

This AppleScript will converted special symbols used in these forums to a form not used by the forum software in order to preserve the original characters.

For the symbols, see:
See "Other formating tags are available as shown below" in
http://discussions.apple.com/help.jspa&#035;format

An alternative to using these symbols is document in this post:
http://discussions.apple.com/thread.jspa?messageID=607563

Also, this AppleScript preserves indentation used in programs or Terminal output.

a) Copy the text to the clipboard .
b) Run this AppleScript to convert the text
c) Paste the converted text into your post.

For example, the asterisks will be preserved:
mac $ ls *oup*
Youpi Key Editor.plist Youpi Key.app alias

For example, the indentation will be preserved:
on adding folder items to this_folder after receiving dropped_items
repeat with dropped_item_ref in dropped_items
display dialog "dropped files is " & dropped_item_ref
end repeat
end adding folder items to

Author: rccharles

with input from:
red_menace
Nubz N.

Copyright 2009 rccharles
GNU General Public License

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

For a copy of the GNU General Public License see <http://www.gnu.org/licenses/&#062;.

*)

property simpleFormatting : true -- when true use tt tag to enclose; when false use pre tab to enclose

on run
-- Write a message into the event log.
log " --- Starting on " & ((current date) as string) & " --- "

set theClip to the clipboard
log length of theClip

(* added Nov 7, 2009 *)
if length of theClip = 0 then
display dialog "Please copy something to the clip board." giving up after 20
return

else if length of theClip > 33 and characters 1 thru 33 of theClip as string = "http://discussions.apple.com/post" then

(*
for example:
http://discussions.apple.com/post&#033;reply.jspa?messageID=9003196
converts to:
http://discussions.apple.com/message.jspa?messageID=9003196&#035;9003196
*)

display dialog "converting link syntax..." giving up after 2

set theClip to alterString(theClip, "post!reply", "message")
set {frontPart, postNumber} to textToList(theClip, "=")
set theClip to theClip & "#" & postNumber
else
display dialog "converting text..." giving up after 2

-- see http://www.asciitable.com/ for the ASCII translations

-- must be the first change so as not to cause problems.
set theClip to alterString(theClip, "#", "&#035;")

-- You need to use either the numeric form of the HTML symbol or
-- translate HTML character enties as seen below.
set theClip to alterString(theClip, "&amp;", "&amp;amp;")
set theClip to alterString(theClip, " ", "&amp;nbsp;")

-- Preserve single blanks, makes it a little easier to read translated code

-- converts two spaces to a space and non-breaking space
set theClip to alterString(theClip, " ", " ")

-- A leading blank will get deleted, so avoid a leading blank -- a blank after a return.

(* ... supports three file formats:
unix (lines end with LF),
dos (lines end with CR LF), and
mac (lines end with CR).
http://vim.wikia.com/wiki/Change&#095;end&#045;of&#045;line&#095;format&#095;for &#095;dos&#045;mac&#045;unix *)

-- Handle Dos return & lf. Perhaps the clipboard was copied from a web page.
-- Reduce to just return since both return & lf act as returns.
-- I've seen this & didn't know what was going on at the time.
set lf to ASCII character 10
set theClip to alterString(theClip, return & lf, return)
-- Handle mac return. And catch a leading blank if any.
set forceLeadingReturn to return & theClip
set forceLeadingReturn to alterString(forceLeadingReturn, return & " ", return & " ")
set theClip to text 2 thru -1 of forceLeadingReturn -- delete prepended return
-- Handle Unix return.
set theClip to alterString(theClip, lf & " ", lf & " ")
-- Change trailing blank return
set theClip to alterString(theClip, " " & return, " " & return) -- mac
set theClip to alterString(theClip, " " & lf, " " & lf) -- unix

-- Avoids multiple returns being converted to a single return / lf.
set theClip to alterString(theClip, return & return, return & " " & return) -- mac
set theClip to alterString(theClip, lf & lf, lf & " " & lf) -- unix


-- I don't think these are order dependent.
set theClip to alterString(theClip, "!", "&#033;")
set theClip to alterString(theClip, "[", "&#091;")
set theClip to alterString(theClip, "]", "&#093;")
set theClip to alterString(theClip, "<", "&#060;")
set theClip to alterString(theClip, "*", "&#042;")
set theClip to alterString(theClip, "+", "&#043;")
set theClip to alterString(theClip, "_", "&#095;")

(* altered Nov 7, 2009 *)
set theClip to alterString(theClip, "-", "&#045;")

set theClip to alterString(theClip, tab, " ") -- Pick three for less spacing.
set theClip to alterString(theClip, "|", "&#124;") -- Gets toasted if in column one
set theClip to alterString(theClip, ">", "&#062;") -- just in case

(* added Nov 7, 2009 *)
set theClip to alterString(theClip, "\\", "&#092;") -- backslash is applescript escape

-- suggested by red_menace from the Mac forums
set theClip to alterString(theClip, "-", "&#45;")
set theClip to alterString(theClip, "^", "&#94;")
set theClip to alterString(theClip, "~", "&#126;")

if simpleFormatting then
set theClip to "<tt>" & theClip & "</tt>"
else
set theClip to addWrapper(theClip)
end if


end if

set the clipboard to theClip

end run

on alterString(thisText, delim, replacement)
set resultList to {}
set {tid, my text item delimiters} to {my text item delimiters, delim}
try
set resultList to every text item of thisText
set text item delimiters to replacement
set resultString to resultList as string
set my text item delimiters to tid
on error
set my text item delimiters to tid
end try
return resultString
end alterString

-- textToList was found here:
-- http://macscripter.net/viewtopic.php?id=15423

on textToList(thisText, delim)
set resultList to {}
set {tid, my text item delimiters} to {my text item delimiters, delim}
try
set resultList to every text item of thisText
set my text item delimiters to tid
on error
set my text item delimiters to tid
end try
return resultList
end textToList

-- ----------------------------------------------------------------------
-- suggested by red_menace from the Mac forums

-- some constants and switches
property TextColor : "#000000" -- black (see http://www.w3schools.com/tags/ref&#095;colornames.asp)
property BackgroundColor : "#FFEE80" -- medium/canary yellow -- "#FFDDFF" -- a light plum/purple
property BorderColor : "#000000" -- black
property TheWidth : "width: 720px; " -- a width attribute
property UseWidth : true -- use the width attribute?
property LineCount : 25 -- the number of lines before including the height attribute
property TheHeight : "height: " & ((LineCount * 13.6) as integer) & "px; " -- a (rough) maximum height for the formatted box

on addWrapper(SomeText)
(*
fix up some formatting and add a tag wrapper (see http://www.w3schools.com/tags/default.asp)
parameters - SomeText text to add the wrapper to
global items - LineCount, TheHeight, UseWidth, TheWidth, KeepFormatting,
BorderColor, TextColor, BackgroundColor
returns [text]: the wrapped text
*)
set {Height, Width} to {"", ""}
if (count paragraphs of SomeText) is greater than LineCount then set Height to TheHeight

if UseWidth then set Width to TheWidth
-- hack...
-- seems like the apple forum software doubles the returns in a pre tag
set SomeText to alterString(SomeText, return, "<br>")

-- change the style properties as needed
set SomeText to "<pre style=\"
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
font-weight: normal;
margin: 0px;
padding: 5px;
border: 1px solid " & BorderColor & ";
" & Width & Height & "
color: " & TextColor & ";
background-color: " & BackgroundColor & ";
overflow: auto;\"
title=\"\">" & SomeText & "</pre>
"
return SomeText
end addWrapper

Update to Format a link and an Applescipt for posting

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