• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Saving to desktop with TextEdit - El Capitan vs Sierra [1]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Saving to desktop with TextEdit - El Capitan vs Sierra [1]


  • Subject: Re: Saving to desktop with TextEdit - El Capitan vs Sierra [1]
  • From: Yvan KOENIG <email@hidden>
  • Date: Tue, 27 Dec 2016 18:08:56 +0100

As I don't know how long we will have to wait for engineers correcting the 10.12.2/10.12.3 bug I wrote a script allowing us to save under these operating systems.

--[SCRIPT]
(*
use AppleScript version "2.4" # Yosemite or later OS
use framework "Foundation"
use scripting additions
*)
set POSIXDestFolder to POSIX path of (path to desktop folder)
set HfsName to "delete/me.rtfd"

tell application "TextEdit"
activate
set thisDocument to make new document
tell thisDocument
set its text to "I‘m a poor lonesome cowboy."
end tell
my saveIt(POSIXDestFolder, HfsName)
close document 1 without saving
end tell

on saveIt(POSIXDestFolder, HfsName)
set theApp to "TextEdit"
if HfsName contains "/" then
set POSIXName to my remplace(HfsName, "/", ":")
else
copy HfsName to POSIXName
end if
if POSIXDestFolder ends with "/" then
set maybe to POSIXDestFolder & POSIXName # POSIXDestFolder was derived from an Hfs path
else
set maybe to POSIXDestFolder & "/" & POSIXName
end if
tell application "System Events"
if exists disk item maybe then delete disk item maybe
tell process theApp
set frontmost to true
keystroke "s" using {command down}
tell window 1
repeat
delay 0.01
if exists sheet 1 then exit repeat
end repeat
tell sheet 1 # Save dialog
--class of UI elements --> {group, button, button, button, group, UI element, text field, static text, static text, text field}
--value of every text field --> {"Sans titre.rtf", ""}
# Defines the name of the file to save
set value of text field 1 to HfsName
-- class of UI elements of group 1 --> {group}
-- class of UI elements of group 1 of group 1 --> {static text, pop up button}
tell pop up button 1 of group 1 of group 1
-- its name --> "Format de fichier :"
-- its value --> "Document RTF"
click it
-- name of menu items of menu 1 --> {"Document RTF", "Format RTF avec pièces jointes", "Page web (.html)", "Document d’archive web", "Document format texte OpenDocument (.odt)", "Document Word 2007 (.docx)", "Document Word 2003 (.xml)", "Document Word 97 (.doc)"}
if HfsName ends with ".rtfd" then
click menu item 2 of menu 1 --> "Format RTF avec pièces jointes"
else
click menu item 1 of menu 1 --> "Document RTF"
end if
end tell # pop up button
keystroke "g" using {command down, shift down}
repeat until exists sheet 1
tell me to delay 0.02
end repeat
tell sheet 1
-- class of UI elements --> {static text, combo box, button, button}
tell me to set sysv2 to (system attribute "sys2")
if sysv2 < 11 then
set theTarget to text field 1
else
set theTarget to combo box 1
end if
# Defines the path of the folder where the file must be saved
set value of theTarget to POSIXDestFolder
-- value of theTarget --> "/Users/yvankoenig/Desktop/"
-- title of buttons --> {"Aller", "Annuler"}
keystroke return # ditto click button 1 (ou Aller)
end tell # sheet 1
-- title of buttons --> {"Enregistrer", "Nouveau dossier", "Annuler"}
click button 1 # ditto click button "Enregistrer"
end tell # sheet 1
end tell # window 1
end tell # process
set oldSize to -10
repeat
delay 0.1
try
set newSize to size of disk item maybe
if newSize = oldSize then exit repeat
set oldSize to newSize
end try
end repeat
end tell # System Events
end saveIt

#=====
(*
replaces every occurences of d1 by d2 in the text t
*)
on remplace(t, d1, d2)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d1}
set l to text items of t
set AppleScript's text item delimiters to d2
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end remplace

#=====
--[/SCRIPT]

It may be used with older systems too.

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) mardi 27 décembre 2016 18:08:02



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Saving to desktop with TextEdit - El Capitan vs Sierra [1] (From: Axel Luttgens <email@hidden>)

  • Prev by Date: Re: Saving to desktop with TextEdit - El Capitan vs Sierra [1]
  • Next by Date: Mail on El Capitan – Message ID Ref Fails to Compile
  • Previous by thread: Re: Saving to desktop with TextEdit - El Capitan vs Sierra [1]
  • Next by thread: Saving to desktop with TextEdit - El Capitan vs Sierra [2]
  • Index(es):
    • Date
    • Thread