I have a single column table view created in IB that is populated with a list of files. These files were chosen from (path to desktop) and reordered. This works fine. I now need to run a subroutine that will make reference to these newly reordered files but not sure of the syntax. I’ve been stuck in the mud on this one for 3 days.
Assuming your table view show the complete POSIXs of the files, you could do something like this:
set allAliases to aliasesofTableView_DataColumn((table view 1 of scroll view 1 of window 1), 1)
on aliasesofTableView_DataColumn(aTableView, anInt)
set aliasList to {}
set allRows to every data row of aTableView
repeat with i in allRows
set posixPath to (content of data cell anInt of i) as string
set fileAlias to (POSIX file posixFile)
set end of aliasList to fileAlias
end repeat
return aliasList
end aliasesofTableView_DataColumn
Hope it helps,
ief2
Hello ief2,
Thanks for the quick response to my post! I am still confused about where to add this code. This is the code I use to bring the files into the table:
on clicked theObject
if name of theObject = "choose" then
set theFolder to choose folder with prompt "Choose the folder containing the files to be merged" default location (path to desktop) without invisibles
tell application "Finder"
set theFiles to every file of theFolder
set theTableViewContents to {}
repeat with aFile in theFiles
tell aFile to set end of theTableViewContents to {its name, it as text}
end repeat
end tell
tell window "merger"
set content of table view 1 of scroll view 1 to theTableViewContents
set enabled of button "merge" to (count theTableViewContents) > 1
end tell
end if
set allows reordering of table view 1 of scroll view 1 of window "merger" to true
set allows multiple selection of table view 1 of scroll view 1 of window "merger" to true
end clicked
After the files are set in the correct order, there is a “merge” button that will trigger a subroutine to do the merging of the files. Code:
on doThisMerge ()
set output_ to (choose file name with prompt "Choose a name and location for the merged file.")
showpanel()
tell application "Finder" to set files_ to files of ???? as alias list -----------the ??? is the missing piece!!!!!!
try
set file_ref to open for access output_ with write permission
repeat with file_ in files_
set text_ to read file_
write (text_ & return) to file_ref starting at eof
end repeat
try
close access file_ref
end try
on error e
display dialog e
try
close access file_ref
end try
end try
hidepanel()
beep
(display alert "Your Merge is Successful.") center
end doThisMerge
THanks again.
What do you exactly mean with merge? (Sorry, my English isn’t that good)
Are you aiming for something like this?
on clicked theObject
-- ===== OPEN =====
if name of theObject is "choose" then
set theFolder to choose folder with prompt "Choose the folder containing the files to be merged" default location (path to desktop) without invisibles
tell application "Finder" to set theFiles to every file of theFolder
set theTableViewContents to {}
repeat with aFile in theFiles
set aFile to aFile as alias
set fileName to name of (info for aFile)
set filePOSIX to POSIX path of aFile
set end of theTableViewContents to {fileName, filePOSIX}
end repeat
tell window "merger"
set content of table view 1 of scroll view 1 to theTableViewContents
set enabled of button "merge" to (count theTableViewContents) > 1
end tell
end if
set allows reordering of table view 1 of scroll view 1 of window "merger" to true
set allows multiple selection of table view 1 of scroll view 1 of window "merger" to true
-- ===== MERGE =====
if name of theObject is "Merge" then
tell window "Merger" to set allRows to every data row of table view 1 of scroll view 1
set myData to {}
repeat with i in allRows
set end of myData to (content of data cell 2 of allRows) as string
set end of myData to return
end repeat
set outputFile to (choose file name with prompt "Choose a name and location for the merged file.")
set OA to open for access outputFile with write permission
try
write (myData as string) to OA starting at 0
close access OA
on error
try
close access OA
end try
end try
end if
end clicked
If you click the “Merge” button it prompts for a file, opens the file for writing and writes all ordered POSIXs to that file.
Hope it helps,
ief2