Date   

Re: TextEdit won't open a plain text file after writing to it with write cmd

Shane Stanley
 

On 18 Jun 2018, at 7:00 pm, Ilya Shebalin <iljashebalin2@gmail.com> wrote:

current date compiles into «event miscued» in SD and my Mac is set to Russian as default language.
OK, so those characters you see are what you need to use in «class utf8». When I change my system and keyboard to Russian, they are option-shift-+ and option-+.

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


Re: TextEdit won't open a plain text file after writing to it with write cmd

Ilya Shebalin
 

actually should've been «event misccurd» (auto-correction in action stood in the way)
18.06.2018, в 8:33, Shane Stanley написал(а):

On 18 Jun 2018, at 3:28 pm, Ilya Shebalin <iljashebalin2@...> wrote:

That's how the as "class utf8" compiles in ScriptDebugger:

Type this into a Script Debugger window:

current date

Compile, then go to the View Menu and choose Show Raw (Chevron) Syntax, and compile again. What do you see now?

Also, what language is your computer set to?

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







Re: TextEdit won't open a plain text file after writing to it with write cmd

Ilya Shebalin
 

current date compiles into «event miscued» in SD and my Mac is set to Russian as default language.
18.06.2018, в 8:33, Shane Stanley написал(а):

On 18 Jun 2018, at 3:28 pm, Ilya Shebalin <iljashebalin2@...> wrote:

That's how the as "class utf8" compiles in ScriptDebugger:

Type this into a Script Debugger window:

current date

Compile, then go to the View Menu and choose Show Raw (Chevron) Syntax, and compile again. What do you see now?

Also, what language is your computer set to?

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







Re: TextEdit won't open a plain text file after writing to it with write cmd

Shane Stanley
 

On 18 Jun 2018, at 3:28 pm, Ilya Shebalin <iljashebalin2@gmail.com> wrote:

That's how the as "class utf8" compiles in ScriptDebugger:
Type this into a Script Debugger window:

current date

Compile, then go to the View Menu and choose Show Raw (Chevron) Syntax, and compile again. What do you see now?

Also, what language is your computer set to?

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


Re: TextEdit won't open a plain text file after writing to it with write cmd

Ilya Shebalin
 

Hello again, Shane
That's how the as "class utf8" compiles in ScriptDebugger:
«class as  »:"class utf8"

18.06.2018, в 2:50, Shane Stanley написал(а):

On 18 Jun 2018, at 2:39 am, Ilya Shebalin <iljashebalin2@...> wrote:

I just have to figure out how to make quotes into as chevrons in precompiled AS code because my default locale is not en_EN. Maybe that's the cause of the error.

Go here and download a copy of Script Debugger: <https://latenightsw.com/sd7/download/>. Open one of your working scripts, then go to the View Menu and choose Show Raw (Chevron) Syntax. That should show you what you need.


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







Re: drafting/prototyping code ?

Maik Waschfeld
 

HI Jean-Christophe,

I want to draft or prototype with real text mixed with code and maybe graphs to get a better idea of the flow.

I’d recommend yEd Graph Editor by yWorks <https://www.yworks.com/>.

It’s Java based and it’s free.

See the Gallery <https://www.yworks.com/products/yfiles/gallery> for examples.


With kindest regards…
…Maik Waschfeld

(sent from my MBAir11)




Re: Automator find and replace text string

Shane Stanley
 

On 18 Jun 2018, at 12:29 am, Alastair Leith <qc.student.au@gmail.com> wrote:

no escape chars either
Escaping/quoting is only required for the shell, so there's no reason for it to appear anywhere other than Terminal, bash scripts, and do shell script.

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


Re: TextEdit won't open a plain text file after writing to it with write cmd

Shane Stanley
 

On 18 Jun 2018, at 2:39 am, Ilya Shebalin <iljashebalin2@gmail.com> wrote:

I just have to figure out how to make quotes into as chevrons in precompiled AS code because my default locale is not en_EN. Maybe that's the cause of the error.
Go here and download a copy of Script Debugger: <https://latenightsw.com/sd7/download/>. Open one of your working scripts, then go to the View Menu and choose Show Raw (Chevron) Syntax. That should show you what you need.


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


Re: TextEdit won't open a plain text file after writing to it with write cmd

Ilya Shebalin
 

I see the difference. I just have to figure out how to make quotes into as chevrons in precompiled AS code because my default locale is not en_EN. Maybe that's the cause of the error. 
17.06.2018, в 9:52, Shane Stanley написал(а):

On 17 Jun 2018, at 3:55 pm, Ilya Shebalin <iljashebalin2@...> wrote:

write theText to FileID as "class utf8"

You're still using quote marks instead of chevrons -- they are not the same things.

write theText to FileID as «class utf8»

Can you see the difference?





Re: Automator find and replace text string

Alastair Leith
 

Much obliged, Shane. Thx.

On 17 Jun 2018, at 8:34 pm, Shane Stanley <sstanley@...> wrote:

On 17 Jun 2018, at 10:23 pm, Jean-Christophe Helary <brandelune@...> wrote:

I don't think I'd use AS for that. I'd use [Run shell script] and do a sed replace on the string you get.

Seems like a bit of overkill for a simple literal replace.

tell application "Finder" to set finderSelectionList to selection as alias list
if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
set thePath to POSIX path of item 1 of finderSelectionList
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"/"}
set thePath to text items of thePath
set AppleScript's text item delimiters to {" "}
set thePath to thePath as text
set AppleScript's text item delimiters to saveTID
set the clipboard to thePath




Re: Automator find and replace text string

2551phil
 

On 17 Jun 2018, at 21:28, Steve Mills <sjmills@mac.com> wrote:

at some point recently, Apple added command-option-c


That appeared in El Capitan.

FWIW, aside from the keyboard shortcut and the Edit view menu already mentioned, it is also available in a Finder window if you invoke the contextual menu on a selected item and hold down the option key.


Best


Phil
@sqwarq


Re: Automator find and replace text string

Alastair Leith
 

Thanks Steve! So cool, no escape chars either.

On 17 Jun 2018, at 10:28 pm, Steve Mills <sjmills@mac.com> wrote:

On Jun 17, 2018, at 06:41, Alastair Leith <qc.student.au@gmail.com> wrote:

I often create file path strings for email messages to my team by drawing a file from Finder into terminal and then that resulting text into the Mail body text and Subject line.
BTW, at some point recently, Apple added command-option-c (IIRC) to Finder’s Edit menu to copy the path[s] of the selection, so you can save a big step here.

Steve via iPad


Re: Automator find and replace text string

Shane Stanley
 

On 17 Jun 2018, at 10:23 pm, Jean-Christophe Helary <brandelune@...> wrote:

I don't think I'd use AS for that. I'd use [Run shell script] and do a sed replace on the string you get.

Seems like a bit of overkill for a simple literal replace.

tell application "Finder" to set finderSelectionList to selection as alias list
if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
set thePath to POSIX path of item 1 of finderSelectionList
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"/"}
set thePath to text items of thePath
set AppleScript's text item delimiters to {" "}
set thePath to thePath as text
set AppleScript's text item delimiters to saveTID
set the clipboard to thePath



Automator find and replace text string

Alastair Leith
 

Is there a basic find and replace text function in Automator? I can only find one for file name strings to use in the Finder (And I don’t want to change any file names, just copy their paths and display in a modified way.


Background

I often create file path strings for email messages to my team by drawing a file from Finder into terminal and then that resulting text into the Mail body text and Subject line.

E.g.
/Users/aleith/pCloud\ Drive/Screenshots/reseeding\ coral\ on\ GBR.jpg 

Then to be kind to non-techies I often replace all escaped characters will just the character and directory symbols “ ➤ “ with and arrow “➤” or something.

➤ Users ➤ aleith ➤ pCloud Drive ➤ Screenshots ➤ reseeding coral on GBR.jpg 

Apart from fact that Find and Replace in Mail is buggy as hell (only thing that works properly is ‘Replace All', which sometimes is the last thing I want to do as in example above), I figured why not make it all a contextual menu service in Finder so I select the files(s) and it generates a text string which then is copied to the clipboard.

I know I can write an AppleScript to do text substitution and copy to Clipboard, and then make that an Automator service, but surprised me I couldn’t find anything in Automator itself other than the Rename Finder Item, the only action that comes up when I search for “replace”.


Re: TextEdit won't open a plain text file after writing to it with write cmd

Shane Stanley
 

On 17 Jun 2018, at 3:55 pm, Ilya Shebalin <iljashebalin2@...> wrote:

write theText to FileID as "class utf8"

You're still using quote marks instead of chevrons -- they are not the same things.

write theText to FileID as «class utf8»

Can you see the difference?




Re: TextEdit won't open a plain text file after writing to it with write cmd

Ilya Shebalin
 

Here's slightly modified the original 1st script:
#########The script No.1. I got the coercion error number -1700 ("couldn't coerce the_text to "class salc"")
property theText : ""
property theFile : missing value
property theSubject : ""
tell application "Mail"


set TheNotes to (get selection)
repeat with aNote in TheNotes
if subject of aNote contains ":" then set CorrectedSubject to my FindandReplace(":", space, subject of aNote)
set {theText, theSubject} to {content of aNote, CorrectedSubject}


end repeat
end tell
tell application "Finder"
set theName to theSubject & ".txt"
set FullFilePath to ((path to desktop as text) & theName)
if not (file FullFilePath exists) then
set theDoc to make new document file with properties {name:theName, displayed name:theName} at folder "Desktop" of home
tell application "TextEdit"
activate
set MyDoc to make new document with properties {text:theText, name:theName} at end of documents
close MyDoc saving in (FullFilePath as alias)
quit
end tell
else
set theFile to (FullFilePath as alias)
set theText to theText
set theDialog to display dialog "The document already exists. " & return & "Would you like to update it?" buttons {"No", "Yes"} default button 2 cancel button 1
if button returned of result is "No" then
error number -128
else
try
my writeToFile(theText, theFile)
on error number -49
close access theFile
end try
my writeToFile(theText, theFile)
end if
end if
end tell

on writeToFile(theText, theFile)
set FileID to open for access theFile with write permission
set eof FileID to 0
write theText to FileID as "class utf8"
close access FileID
end writeToFile

on FindandReplace(SearchItem, ReplacementItem, theString)
get theString
set AppleScript's text item delimiters to SearchItem
set TempText to text items of theString
set AppleScript's text item delimiters to ReplacementItem
set theString to TempText as text
end FindandReplace



#################The script No.2. A rough version of the 1st one, for the sake of keeping bare bone structure only. Runs flawlessly.

property theText : ""
property theFile : missing value
tell application "Finder"


set theName to "103" --can be changed to any name
set theExtension to "txt" --can be changed to any extension
set FullFilePath to (((path to desktop) as text) & theName & "." & theExtension)
if not (file FullFilePath exists) then
set theText to "This is test of writing text to a file and closing access to it."
set theDoc to make new document file with properties {name:theName & "." & theExtension, displayed name:theName} at folder "Desktop" of home
tell application "TextEdit"
activate


set myDoc to make new document with properties {text:theText, name:theName & "." & theExtension} at end of documents
close myDoc saving in (FullFilePath as alias)

quit

end tell
else
set theFile to FullFilePath as alias
set theText to "This is another text"


set theDialog to display dialog "The document already exists. " & return & "Write another text to it?" buttons {"No", "Yes"} default answer "" default button 2 cancel button 1
if button returned of result is "No" then
error number -128
else
set theText to text returned of theDialog
my writeUTF16(theText, theFile)
end if
end if
end tell

on writeUTF16(theText, theFile)
set FileID to open for access theFile with write permission
set theEnd to get eof FileID
write theText to FileID as Unicode text starting at theEnd
close access FileID
end writeUTF16





16.06.2018, в 9:51, Shane Stanley написал(а):

On 16 Jun 2018, at 3:40 pm, Ilya Shebalin <iljashebalin2@...> wrote:

Here's my script (copy pasted as plain text) and another following that one.

I'm no longer sure what your question is. Neither use the suggested code. And the second one is problematic if the file already exists and is longer than the text you're writing.

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







Re: drafting/prototyping code ?

Alastair Leith
 

Keynote is great for drawing programming flow type diagrams, there dedicated tools for this also, like Balsamiq, but I don't know of one other than Keynote that is free. Here's an example file from a project of mine.


Re: TextEdit won't open a plain text file after writing to it with write cmd

Ilya Shebalin
 

It seems you don't own me apology, Shane. My 1st script was butchered at some point missing some lines previously present perhaps because of numerous copy pastes between ScriptEditor and Mail messages in reply to this thread. A hidden issue manifested when AppleScript traditionally failed on ":" character (it bothers me, seriously; they could implement some solutions to AS in that regard. Annoying). I'm working on it right now.
16.06.2018, в 15:46, Shane Stanley написал(а):

On 16 Jun 2018, at 10:08 pm, Ilya Shebalin <iljashebalin2@gmail.com> wrote:

I'm not sure I can interpret your response correctly.
My apologies -- I misread your code.

I'm still not sure what the problem was with «class utf8».

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





Re: TextEdit won't open a plain text file after writing to it with write cmd

Shane Stanley
 

On 16 Jun 2018, at 10:08 pm, Ilya Shebalin <iljashebalin2@gmail.com> wrote:

I'm not sure I can interpret your response correctly.
My apologies -- I misread your code.

I'm still not sure what the problem was with «class utf8».

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


Re: TextEdit won't open a plain text file after writing to it with write cmd

Ilya Shebalin
 

I'm not sure I can interpret your response correctly. The second script is a tad modified version of the 1st one. On the very 1st run it creates a new text doc, on every consecutive one it offers 2 options: dismiss writing or write another text by appending it to the target file. I just ran it successfully in that it creates a file and if it's updated with writing new text it allows me to open it in TextEditor. The 1st script works too except TextEdit won't open the file. To run the second script on different file all you have to do is to change the Name variable assigning to it another word as a name.
16.06.2018, в 9:51, Shane Stanley написал(а):

On 16 Jun 2018, at 3:40 pm, Ilya Shebalin <iljashebalin2@gmail.com> wrote:

Here's my script (copy pasted as plain text) and another following that one.
I'm no longer sure what your question is. Neither use the suggested code. And the second one is problematic if the file already exists and is longer than the text you're writing.

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




41 - 60 of 275