• 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
Script to save and restore a session in TextEdit
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Script to save and restore a session in TextEdit


  • Subject: Script to save and restore a session in TextEdit
  • From: Joseph Weaks <email@hidden>
  • Date: Tue, 17 Jun 2003 21:04:24 -0500

Here's the script I was writing when I asked about saving script properties. I use TextEdit alot, and wanted an easy way to save what windows were open along with their locations so that the session might be restored later. This script creates a script that restores what was the current session in TextEdit.
I used a few 'ugly' work-arounds, so feel free to point out places where there is an easier way.
Cheers,
Joe Weaks

(* This script reads all currently open windows in TextEdit and then creates a script that will open up the same documents with the same window positions. Written by Joe Weaks, 2003. *)

property allWindowBounds : {}
property allDocumentAliases : {}

tell application "TextEdit" to set winList to windows
repeat with eachWindow in winList
tell application "TextEdit" to set winBounds to bounds of eachWindow
copy winBounds to end of allWindowBounds
end repeat

tell application "TextEdit" to set docList to documents
repeat with eachDocument in docList
tell application "TextEdit" to set docPath to path of eachDocument
-- Path needs to be changed for / format to : format
set OTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set docPath to text items of docPath
set AppleScript's text item delimiters to ":"
if (item 2 of docPath) = "Volumes" then
set docPath to (items 3 thru -1 of docPath) as string
else
set docPath to (items 1 thru -1 of docPath) as string
end if
set AppleScript's text item delimiters to OTID
try
set docAlias to docPath as alias
on error theError
-- The path to a document raised an error due to special characters
display dialog "One of the windows won't set. " & theError
set docAlias to ""
end try
set allDocumentAliases to allDocumentAliases & docAlias
end repeat

-- Get name and file path of saved file
set scriptDialog to display dialog "What would you like to call this session?" default answer ((current date) as string) buttons {"Desktop", "Home", "Other"}
if button returned of scriptDialog is "Desktop" then
set theDestination to (path to desktop)
else if button returned of scriptDialog is "Home" then
set theDestination to (path to current user folder)
else
set theDestination to (choose folder)
end if
set scriptName to text returned of scriptDialog

set scriptPath to (theDestination as string) & scriptName

script customScript
property theWindows : {}
property theDocuments : {}
repeat with x from (count of theDocuments) to 1 by -1
set DocToOpen to item x of theDocuments
tell application "TextEdit" to open DocToOpen
set windowBounds to (item x of theWindows)
tell application "TextEdit" to set bounds of front window to windowBounds
end repeat
end script

tell customScript
set its theWindows to allWindowBounds
set its theDocuments to allDocumentAliases
end tell

store script customScript in file scriptPath with replacing
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: A script to create another script (From: John Delacour <email@hidden>)

  • Prev by Date: Re: AppleScript Timed Events
  • Next by Date: Re: AppleScript Timed Events
  • Previous by thread: Re: A script to create another script
  • Next by thread: Re: Why save text item delimiters? Philosophical question....
  • Index(es):
    • Date
    • Thread