Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

motulist

macrumors 601
Original poster
Dec 2, 2003
4,235
611
I use this guy's awesome concatenating script all the time. I am not a programmer at all, but I want to change the default save location to being the folder that the drag and dropped source files came from instead of defaulting to the desktop as it does now. What needs to be changed?

If you want to see the code clearer, just download the apple script and open it in the apple script editor.


Code:
-- Catenator v1.1.0, ©2004 Frozen Heads Software and Colin Foster
--
-- Web: http://www.frozenheads.com/
--
-- You are welcome to reuse parts of this script in your scripts, but
-- it would be nice if I got a mention for anything you use.
--
-- This script may not be redistributed with any modifications, but 
-- please feel free to make any suggestions you feel would improve it
-- to either email address above.  Thanks!


property DISALLOWED_KINDS : "Volume Folder"
display dialog "If you drag & drop some files onto this program's icon, they will be sorted alphabetically and then concatenated together." buttons {"OK"} default button 1

------------------------------------------------------------------------------------------------------
-- open
--
-- [Colin A. Foster, 2004.08.21]
------------------------------------------------------------------------------------------------------

on open (item_list)
	
	activate me
	set bad_kind to false
	
	-- Convert drag & dropped files from aliases to text paths.
	set text_list to {}
	
	repeat with one_item in item_list
		set text_list to text_list & (one_item as text)
	end repeat
	
	-- Sort them in alphabetical order.
	set item_list to quickSort(text_list)
	
	-- Base of shell script command.
	set shell_script to "cat -u "
	
	-- For each file name, add its path to the command.
	repeat with one_item in item_list
		
		tell application "Finder"
			
			set one_item_alias to one_item as alias
			set item_kind to kind of one_item_alias -- What kind of item is this?
			
			if (DISALLOWED_KINDS does not contain item_kind) then -- Is it a document?
				set posix_item to quoted form of POSIX path of one_item -- UNIX path of specified file.
				set shell_script to shell_script & posix_item & " "
			else -- If not a document, flag the process as missing some files.
				set bad_kind to true
				set bad_item to one_item
			end if
		end tell
	end repeat
	
	if (bad_kind) then -- Does the user want to abort based on some files being omitted?
		display dialog "WARNING: Some items you have dropped onto this program cannot be catenated (Volume or Folder). They will not be included in the final output." & return & return & (bad_item as text) buttons {"Cancel", "Continue"} default button "Continue"
	end if
	
	set suggested_name to make_suggested_name(item 1 of item_list) -- Create a default name based on dropped files.
	set desktop_path to path to desktop folder
	set save_location to choose file name with prompt "Files will be sorted by path then merged into the following file:" default name suggested_name default location desktop_path
	
	set posix_save to quoted form of POSIX path of save_location -- UNIX path of specified output file.
	
	-- Tack on ending for the shell script command (redirect output to the above file).
	set shell_script to shell_script & ">" & posix_save
	
	try
		do shell script shell_script
	on error msg
		display dialog "Error: " & msg
	end try
	
end open


------------------------------------------------------------------------------------------------------
-- make_suggested_name
--
-- [Colin A. Foster, 2004.08.21]
------------------------------------------------------------------------------------------------------

on make_suggested_name(suggested_item)
	
	tell application "Finder" to set full_name to name of item suggested_item
	
	try
		tell application "Finder" to set item_ext to name extension of item suggested_item
		set suggested_name to (text 1 through ((offset of item_ext in full_name) - 2) of full_name)
		if (length of suggested_name is less than 2) then
			set suggested_name to full_name
		end if
	on error
		set suggested_name to full_name
	end try
	
	return suggested_name
	
end make_suggested_name


------------------------------------------------------------------------
--property author : "Serge Belleudy-d'Espinose"
--property modVersion : "1.0"
--property modName : "qSort"
--property releaseDate : date "Friday, September 28, 2001 12:00:00 AM"
--property requiredParams : "list"
------------------------------------------------------------------------

on quickSort(xList)
	
	script xObject
		
		property xList : {}
		property lowList : {}
		property highList : {}
		
	end script
	
	set {rxList, rLowList, rHighList} to {¬
		a reference to xObject's xList, ¬
		a reference to xObject's lowList, ¬
		a reference to xObject's highList}
	
	set rxList's contents to xList
	set xLength to rxList's contents's length
	
	if not (xLength > 1) then
		set xResult to xList
		
	else if xLength = 2 then
		set {xItem, yItem} to ¬
			rxList's contents
		
		if xItem > yItem then ¬
			set {rxList's contents's item 1, rxList's contents's item 2} to ¬
				{yItem, xItem}
		
		set xResult to xList
		
	else -- xLength > 2
		set xMiddle to (xLength + 1) div 2
		set xPivot to rxList's contents's item xMiddle
		
		repeat with i from 1 to (xMiddle - 1)
			set xItem to rxList's contents's item i
			
			if xItem < xPivot then
				set rLowList's contents's end to xItem
			else
				set rHighList's contents's end to xItem
			end if
			
		end repeat
		
		repeat with i from (xMiddle + 1) to xLength
			set xItem to rxList's contents's item i
			
			if xItem < xPivot then
				set rLowList's contents's end to xItem
			else
				set rHighList's contents's end to xItem
			end if
			
		end repeat
		
		if rLowList's contents is not {} then ¬
			set rLowList's contents to quickSort(rLowList's contents)
		
		if rHighList's contents is not {} then ¬
			set rHighList's contents to quickSort(rHighList's contents)
		
		set xResult to rLowList's contents & xPivot & rHighList's contents
		
	end if
	
	return xResult
	
end quickSort
 

xUKHCx

Administrator emeritus
Jan 15, 2006
12,583
9
The Kop
Believe this will work, see following post for the specific bits i have added.

Code:
-- Catenator v1.1.0, ©2004 Frozen Heads Software and Colin Foster
--
-- Web: http://www.frozenheads.com/
--
-- You are welcome to reuse parts of this script in your scripts, but
-- it would be nice if I got a mention for anything you use.
--
-- This script may not be redistributed with any modifications, but 
-- please feel free to make any suggestions you feel would improve it
-- to either email address above.  Thanks!


property DISALLOWED_KINDS : "Volume Folder"
display dialog "If you drag & drop some files onto this program's icon, they will be sorted alphabetically and then concatenated together." buttons {"OK"} default button 1

------------------------------------------------------------------------------------------------------
-- open
--
-- [Colin A. Foster, 2004.08.21]
------------------------------------------------------------------------------------------------------

on open (item_list)
	
	activate me
	set bad_kind to false
	
	-- Convert drag & dropped files from aliases to text paths.
	set text_list to {}
	
	repeat with one_item in item_list
		set text_list to text_list & (one_item as text)
	end repeat
	tell application "Finder"
		set save_loc1 to container of one_item as alias
	end tell
	-- Sort them in alphabetical order.
	set item_list to quickSort(text_list)
	
	-- Base of shell script command.
	set shell_script to "cat -u "
	
	-- For each file name, add its path to the command.
	repeat with one_item in item_list
		
		tell application "Finder"
			
			set one_item_alias to one_item as alias
			set item_kind to kind of one_item_alias -- What kind of item is this?
			
			if (DISALLOWED_KINDS does not contain item_kind) then -- Is it a document?
				set posix_item to quoted form of POSIX path of one_item -- UNIX path of specified file.
				set shell_script to shell_script & posix_item & " "
			else -- If not a document, flag the process as missing some files.
				set bad_kind to true
				set bad_item to one_item
			end if
		end tell
	end repeat
	
	if (bad_kind) then -- Does the user want to abort based on some files being omitted?
		display dialog "WARNING: Some items you have dropped onto this program cannot be catenated (Volume or Folder). They will not be included in the final output." & return & return & (bad_item as text) buttons {"Cancel", "Continue"} default button "Continue"
	end if
	
	set suggested_name to make_suggested_name(item 1 of item_list) -- Create a default name based on dropped files.
	set desktop_path to path to desktop folder
	set save_location to choose file name with prompt "Files will be sorted by path then merged into the following file:" default name suggested_name default location save_loc1
	
	set posix_save to quoted form of POSIX path of save_location -- UNIX path of specified output file.
	
	-- Tack on ending for the shell script command (redirect output to the above file).
	set shell_script to shell_script & ">" & posix_save
	
	try
		do shell script shell_script
	on error msg
		display dialog "Error: " & msg
	end try
	
end open


------------------------------------------------------------------------------------------------------
-- make_suggested_name
--
-- [Colin A. Foster, 2004.08.21]
------------------------------------------------------------------------------------------------------

on make_suggested_name(suggested_item)
	
	tell application "Finder" to set full_name to name of item suggested_item
	
	try
		tell application "Finder" to set item_ext to name extension of item suggested_item
		set suggested_name to (text 1 through ((offset of item_ext in full_name) - 2) of full_name)
		if (length of suggested_name is less than 2) then
			set suggested_name to full_name
		end if
	on error
		set suggested_name to full_name
	end try
	
	return suggested_name
	
end make_suggested_name


------------------------------------------------------------------------
--property author : "Serge Belleudy-d'Espinose"
--property modVersion : "1.0"
--property modName : "qSort"
--property releaseDate : date "Friday, September 28, 2001 12:00:00 AM"
--property requiredParams : "list"
------------------------------------------------------------------------

on quickSort(xList)
	
	script xObject
		
		property xList : {}
		property lowList : {}
		property highList : {}
		
	end script
	
	set {rxList, rLowList, rHighList} to {¬
		a reference to xObject's xList, ¬
		a reference to xObject's lowList, ¬
		a reference to xObject's highList}
	
	set rxList's contents to xList
	set xLength to rxList's contents's length
	
	if not (xLength > 1) then
		set xResult to xList
		
	else if xLength = 2 then
		set {xItem, yItem} to ¬
			rxList's contents
		
		if xItem > yItem then ¬
			set {rxList's contents's item 1, rxList's contents's item 2} to ¬
				{yItem, xItem}
		
		set xResult to xList
		
	else -- xLength > 2
		set xMiddle to (xLength + 1) div 2
		set xPivot to rxList's contents's item xMiddle
		
		repeat with i from 1 to (xMiddle - 1)
			set xItem to rxList's contents's item i
			
			if xItem < xPivot then
				set rLowList's contents's end to xItem
			else
				set rHighList's contents's end to xItem
			end if
			
		end repeat
		
		repeat with i from (xMiddle + 1) to xLength
			set xItem to rxList's contents's item i
			
			if xItem < xPivot then
				set rLowList's contents's end to xItem
			else
				set rHighList's contents's end to xItem
			end if
			
		end repeat
		
		if rLowList's contents is not {} then ¬
			set rLowList's contents to quickSort(rLowList's contents)
		
		if rHighList's contents is not {} then ¬
			set rHighList's contents to quickSort(rHighList's contents)
		
		set xResult to rLowList's contents & xPivot & rHighList's contents
		
	end if
	
	return xResult
	
end quickSort
 

xUKHCx

Administrator emeritus
Jan 15, 2006
12,583
9
The Kop
Firstly defined a new variable sav_loc1 which is the parent folder of the items being dropped

tell application "Finder"
set save_loc1 to container of one_item as alias
end tell

I then altered this line

set save_location to choose file name with prompt "Files will be sorted by path then merged into the following file:" default name suggested_name default location desktop_path

to

set save_location to choose file name with prompt "Files will be sorted by path then merged into the following file:" default name suggested_name default location save_loc1

Mod note: Split into two posts because it is easier to show what was needed to be change by using separate posts.

That worked!!! You're a genius man! Thanks! :D

Thats alright, not really a genius though but thanks anyway
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.