G’day from Oz
Last year, under Tiger, I wrote an Studio App that retrieved info from desktop folders. Now I’ve upgraded to Leopard and I’ve put the folders into a single desktop folder called ‘Mail Printing Folder’, and of course my App can’t find them.
I’ve tried to re-write the Applescript, and keep getting errors with the formatting, starting with the ‘launched’ command.
I’ve searched for an answer but can’t find anything. Has the Applescript format for Studio been updated?
I’ll post my code below,and ask if anyone can guide me on the correct format, or if not, perhaps a site where I can find the correct information.
Thanks, and regards
Santa
-- rtfd Loader.applescript
-- rtfd Loader
-- Created by Brian on 7/08/07.
-- Copyright 2007 __MeSelf__. All rights reserved.
global theDataSource
global datasource2
global DeskTopPath
global theWindow
global SelectedItem
global theYear
property theSenderList : {}
property thertfdList : {}
property finalList : {}
property SenderFlag : false
property rtfdFlag : false
property contactsDataSource : null
on launched theObject
-- Show the main window
set the visible of window 1 to true
end launched
on action theObject
if name of theObject is "myTableView" then
my showrtfds()
end if
if name of theObject is "rtfd Table" then
my Getrtfd()
end if
if name of theObject is "Year selector" then
set content of table view 1 of scroll view 1 of split view 1 of theWindow to {}
set content of table view "rtfdtable" of scroll view "rtfdscroll" of split view 1 of theWindow to {}
set contents of text field "messages" of theWindow to "Select a year, and click the magnifying glass icon."
set contents of text field "SearchIn" of theWindow to "Search for rtfd in...."
set the thertfdList to {}
set SenderFlag to false
set rtfdFlag to false
end if
end action
on awake from nib theObject
set DeskTopPath to path to desktop
if name of theObject is "Year selector" then
tell application "Finder"
set the_list to every item offolder "Mail Printing Folder" of desktop
set temp_list to {}
repeat with AnItem in the_list
set theName to name of AnItem
if the theName contains "Mail Data" and class of AnItem is folder and (count of theName) = 14 then
set end of temp_list to name of AnItem
end if
end repeat
end tell
if (count of temp_list) > 0 then
tell theWindow
delete every menu item of menu of popup button "Year selector"
repeat with each_Item in temp_list
make new menu item at the end of menu items of menu of popup button "Year selector" with properties {name:each_Item, title:each_Item, enabled:true}
end repeat
end tell
else
display dialog "There does not seem to be any 'Mail Data' folders on this desktop."
end if
end if
-----
if name of theObject is "cancel" then
quit me
end if
end awake from nib
on clicked theObject
if name of theObject is "Go button" then
my ShowSender()
end if
end clicked
on double clicked theObject
if name of theObject is "myTableView" then
set rowIndex to clicked row of theObject
if rowIndex is greater than 0 then
tell theObject
set xx to selected row
if xx > 0 then set select_item to content of item xx of (get sorted data rows of data source of it)
end tell
set theName to |Sender| of select_item & "<" & |Email address| of select_item & ">"
my showrtfds(theName)
end if
end if
if name of theObject is "rtfdtable" then
set rowIndex to clicked row of theObject
if rowIndex is greater than 0 then
tell theObject
set xx to selected row
if xx > 0 then set select_item to content of item xx of (get sorted data rows of data source of it)
end tell
set theName to |rtfd name| of select_item
my Getrtfd(theName)
end if
end if
end double clicked
on will open theObject
set theWindow to the theObject
tell progress indicator "progress" of theWindow
stop
set indeterminate to false
set contents to 0
end tell
set contents of text field "messages" of theWindow to "Select a year, and click the magnifying glass icon."
end will open
on mouse entered theObject event theEvent
if name of theObject is "Year selector" then
set contents of text field "messages" of theWindow to "Select a year, and click the magnifying glass icon."
end if
if name of theObject is "myTableView" and SenderFlag then
set contents of text field "messages" of theWindow to "Just click once on a Sender name."
end if
if name of theObject is "rtfdScroll" and rtfdFlag then
set contents of text field "messages" of theWindow to "Just click once on an rtfd name."
end if
end mouse entered
on choose menu item theObject
set theCommand to tag of theObject
if theCommand = 0 then
tell application "rtfd Loader 20-24-14"
activate
set visible of window 1 to true
end tell
end if
end choose menu item
-- The "column clicked" event handler is called when the user clicks on a table column in the table view. We will use this handler to change the sort column of the data source as well as the sort order.
--
on column clicked theObject table column tableColumn
try
-- Get the data source of the table view
set theDataSource to data source of theObject
-- Get the identifier of the clicked table column
set theColumnIdentifier to identifier of tableColumn
-- Get the current sort column of the data source
set theSortColumn to sort column of theDataSource
-- If the current sort column is not the same as the clicked column then switch the sort column
if (name of theSortColumn) is not equal to theColumnIdentifier then
set the sort column of theDataSource to data column theColumnIdentifier of theDataSource
else
-- Otherwise change the sort order
if sort order of theSortColumn is ascending then
set the sort case sensitivity of theSortColumn to case insensitive
set sort order of theSortColumn to descending
else
set the sort case sensitivity of theSortColumn to case insensitive
set sort order of theSortColumn to ascending
end if
end if
-- We need to update the table view (so it will be redrawn)
update theObject
end try
end column clicked
on will become active theObject
set visible of window 1 to true
end will become active
--__________________________________________________________________________________________
on SetrtfdColumns()
set theObject to table view 1 of scroll view 2 of split view 1 of theWindow
-- Get the data source of the table view
set theDataSource to data source of theObject
set the sort column of theDataSource to data column "rtfd name" of theDataSource
set the sort case sensitivity of the sort column of theDataSource to case insensitive
set sorted of theDataSource to true
end SetrtfdColumns
on ShowSender()
set content of table view 1 of scroll view 1 of split view 1 of theWindow to {}
set content of table view "rtfdtable" of scroll view "rtfdscroll" of split view 1 of theWindow to {}
set SelectedItem to title of current menu item of popup button "Year selector" of theWindow as string
if SelectedItem ≠"" then
set theYear to characters -4 thru end of SelectedItem as string
set temppath to DeskTopPath & SelectedItem as string
tell application "Finder"
set theFilelist to every item of folder temppath
set thecounter to count of theFilelist
end tell
tell progress indicator "progress" of theWindow
set indeterminate to false
set minimum value to 0
set maximum value to thecounter
set contents to 0
end tell
set theSenderList to {}
set contents of text field "messages" of theWindow to "Please wait."
set TheEmailAddress to {}
repeat with EachPage in theFilelist
tell progress indicator "progress" of theWindow to increment by 1
set WholeList to (read file (EachPage as string) using delimiter return) as list
repeat with x in items of WholeList
try
set xx to my textToList(x, ",")
if (count of xx) > 3 and "<" is in item 3 of xx then
set item 2 of xx to item 2 of xx & "." & item 3 of xx
set item 3 of xx to item 4 of xx
end if
if item 2 of xx is not in theSenderList then
set end of theSenderList to item 2 of xx
set end of TheEmailAddress to my extractAddressName(item 2 of xx)
end if
end try
end repeat
end repeat
delay 0.5
tell progress indicator "progress" of theWindow
stop
set contents to 0
end tell
set contents of text field "messages" of theWindow to "Now click on a Sender to make an rftd list from."
set SenderFlag to true
my addMessage(TheEmailAddress)
end if
end ShowSender
on addMessage(TheEmailAddress)
set theDataSource to table view 1 of scroll view 1 of split view 1 of theWindow
set content of theDataSource to TheEmailAddress
set theObject to table view 1 of scroll view 1 of split view 1 of theWindow
if name of theObject is "myTableView" then
-- Get the data source of the table view
set theDataSource to data source of theObject
set the sort column of theDataSource to data column "Sender" of theDataSource
set the sort case sensitivity of the sort column of theDataSource to case insensitive
set sorted of theDataSource to true
end if
my SetrtfdColumns()
end addMessage
on showrtfds(theSender)
set temppath to DeskTopPath & SelectedItem as string
tell application "Finder"
set theFilelist to every item of folder temppath
set thecounter to count of theFilelist
end tell
tell progress indicator "progress" of theWindow
set indeterminate to false
set minimum value to 0
set maximum value to thecounter
set contents to 0
end tell
set finalList to {}
set thertfdList to {}
set contents of text field "messages" of theWindow to "Please wait."
repeat with EachPage in theFilelist
tell progress indicator "progress" of theWindow to increment by 1
set WholeList to (read file (EachPage as string) using delimiter return) as list
repeat with x in items of WholeList
set xx to my textToList(x, ",")
try
if (count of xx) > 3 and "<" is in item 3 of xx then
set item 2 of xx to item 2 of xx & "." & item 3 of xx
set item 3 of xx to item 4 of xx
end if
if "<" is not in item 2 of xx then set item 2 of xx to "<" & item 2 of xx & ">"
set temp to characters 3 thru -3 of theSender
if item 2 of xx = theSender or temp is in item 2 of xx then
set end of finalList to {item 1 of xx, item 3 of xx, item 2 of xx}
set end of thertfdList to item 1 of xx
end if
end try
end repeat
end repeat
set content of table view "rtfdtable" of scroll view "rtfdscroll" of split view 1 of theWindow to finalList
delay 0.5
tell progress indicator "progress" of theWindow
stop
set contents to 0
end tell
set contents of text field "messages" of theWindow to "Please now select an rtfd."
set rtfdFlag to true
end showrtfds
on Getrtfd(thertfd)
set temppath to DeskTopPath & SelectedItem as string
set errorflag to false
set NoFolderFlag to false
set the SearchPath to the title of current menu item of popup button "Search" of theWindow as string
if SearchPath = "Desktop Yearly folder" then set SearchPath to "Yearly Orders " & theYear
if SearchPath = "Server Daily folder" then set SearchPath to "Taz.VOL1:Art Dept:!preflight_art:Daily Email Orders"
if SearchPath = "Server Yearly folder" then set SearchPath to "Taz.VOL1:Art Dept:!preflight_art:Yearly Email Orders " & theYear
tell application "Finder"
set FileName to SearchPath
if exists folder FileName then
set theFilelist to every item of (entire contents of folder FileName) whose name is thertfd & ".rtfd"
if theFilelist = {} then
set errorflag to true
end if
repeat with x in theFilelist
tell application "TextEdit"
try
open x as alias
end try
end tell
end repeat
else
set NoFolderFlag to true
end if
end tell
if NoFolderFlag then
set theSound to (load sound "/System/Library/Sounds/Glass.aiff")
play theSound
delete theSound
repeat 16 times
set contents of text field "messages" of theWindow to ""
delay 0.1
set contents of text field "messages" of theWindow to "The data folder " & FileName & " couldn't be found."
delay 0.2
end repeat
end if
if errorflag then
set theSound to (load sound "/System/Library/Sounds/Glass.aiff")
play theSound
delete theSound
repeat 16 times
set contents of text field "messages" of theWindow to ""
delay 0.1
set contents of text field "messages" of theWindow to "Document " & thertfd & " couldn't be found."
delay 0.2
end repeat
end if
end Getrtfd
on extractAddressName(theitem)
set temp to my textToList(theitem, "<")
try
if (count of items in temp) = 1 then set temp to {"", temp}
set item 2 of temp to my replace_chars(item 2 of temp, ">", "")
end try
return temp
end extractAddressName
on replace_chars(this_text, search_string, replacement_string)
set KeepDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to KeepDelimiters
return this_text
end replace_chars
on textToList(theText, theSep)
set {myTID, my text item delimiters} to {my text item delimiters, theSep}
set soFar to text items of theText
set my text item delimiters to myTID
return soFar
end textToList
on sort_list(theList)
set nl to (ASCII character 10)
tell (a reference to my text item delimiters)
set {old_delim, contents} to {contents, nl}
set {theList, contents} to {"" & theList, old_delim}
end tell
return paragraphs of (do shell script "echo " & (quoted form of theList) & " | sort")
end sort_list
on clearMessages()
tell scroll view "rtfd Scroll" of split view 1 of theWindow
tell data source of table view "messages" to delete every data row
end tell
end clearMessages
Model: intel iMac
Browser: Safari 525.18
Operating System: Mac OS X (10.5)