After file move by script, document missing its application

I have applications that process InDesign files. They reside on a Windows file server. All documents always have their file extension “.indd”. In Snow Leopard, when a file is moved from folder A to folder B, sometimes a user can no longer double click on the file to open it in InDesign. The document shows that there is no application associated with the document; but the document icon clearly still is an InDesign icon for the user. An error message from the Finder usually says something like “can’t open application null” (not the exact wording). Our user’s computers have InDesign CS3, 4, and 5 installed. They have reset and “changed all” documents to open in InDesign CS3 multiple times. But every couple days this problem shows up, only on files moved around via script.
The script command that I commonly use is a shell script “mv blah blah”. I also do some “Finder tell” moves. I’ve not narrowed it down to using one or the other.
I have looked in my launchservices plist file and it appears that InDesign is set to handle documents ending in .indd. :
LSHandlerContentTag = indd
LSHandlerContentTagClass = public.filename-extension
LSHandlerRoleAll = com.adobe.indesign

Any reason why this information would go away or get corrupted or change ever? Why would this only happen on documents moved by a script?

TIA, Chris

I don’t have a solution but I might have an explanation. I noticed recently that not all file extensions are recognized as extensions. For example, try running this on one of the problem files and see if you get the proper extension.

set theFile to choose file
tell application "Finder"
	set ext to name extension of theFile
end tell

So look at the results and see what you get. My guess is that it will show “” instead of “indd”. If this is the case then you know the problem is that the file extension isn’t being recognized.

I guess you could fix it by re-setting the name extension like this… of course you’d have to reset the name too because it would think that “.indd” was part of the name.

set theFile to choose file
set text item delimiters to "."
tell application "Finder"
	try
		set name of theFile to (text items 1 thru -2 of (get name of theFile)) as text
	end try
	set name extension of theFile to "indd"
end tell
set text item delimiters to ""

Hello.

Maybe this script can help you figure out what exactly has changed, - before and after.
INFO FOR SELECTED ITEMS


-- INFO FOR SELECTED ITEMS
-- ©1998 Sal Soghoian, Apple Computer
(*
	Tinkered By McUsr 2010-04-02 :
	Changed it to take a selcection of files to display info of instead of the usual selection.
	McUsr 2010-07-23 
	Changed it to display a Report in TextEdit
	McUsr 2010-07-25 
	Changed it to have options of both report and dialog, and added the locked and comment property
	to the report.
		McUsr 2010-07-28 
	Added the default application property.
	to the report.

*)

set ReportText to ""
try
	tell me
		activate
		
		set the selected_items_list to (choose file with prompt "Choose the files or folders you want to see info for for" default location (path to me) as alias with multiple selections allowed)
		if the (count of the selected_items_list) is 0 then
			with timeout of 900 seconds
				beep
				display dialog "No files or applications are selected." buttons {"Cancel"} default button 1
			end timeout
		end if
		set last_item to the last item of the selected_items_list as text
		try
			set outputType to button returned of (display dialog "Please choose form of output" buttons {"Cancel", "Report", "Dialogs"} cancel button 1 default button 3 with icon 1)
		on error
			error number -128
		end try
	end tell
	repeat with this_item in the selected_items_list
		if outputType is "Dialogs" then
			set ReportText to ""
		end if
		tell application "Finder"
			
			set this_item to this_item as text
			-- get the information for the item
			set item_info to info for alias this_item
			set item_kind to kind of alias this_item
			set item_comment to comment of alias this_item
			if locked of alias this_item is true then
				set locked_indicator to "True"
			else
				set locked_indicator to "False"
			end if
			
			-- extract the various properties from the stored list
			set item_name to name of item_info
			set file_type to file type of item_info
			set item_creator to file creator of item_info
			set item_size to size of item_info
			set item_creation_date to the creation date of item_info
			set item_modification_date to the modification date of item_info
			set item_version to short version of item_info
			set item_owner to owner of item this_item
			set item_ownerP to owner privileges of item this_item
			set item_group to group of item this_item
			set item_groupP to group privileges of item this_item
			set item_everyonesP to everyones privileges of item this_item
			-- convert the true or false value to text
			set alias_indicator to alias of item_info
			if alias_indicator is true then
				set alias_indicator to "True"
			else
				set alias_indicator to "False"
			end if
		end tell
		tell application "System Events"
			set finfo to properties of item this_item
			
			set ftype to type identifier of finfo
			set defApp to name of default application of finfo
		end tell
		if outputType is "Report" then
			set ReportText to ReportText & return & "==================================" & return & "Name: " & item_name & return
		else
			set ReportText to ReportText & return & "Name: " & item_name & return
		end if
		set ReportText to ReportText & "Pathname: " & POSIX path of (this_item as alias) & return
		set ReportText to ReportText & "Kind: " & item_kind & return
		set ReportText to ReportText & "Comment: " & item_comment & return
		set ReportText to ReportText & "File Type: " & file_type & return
		set ReportText to ReportText & "Creator Code: " & item_creator & return
		set ReportText to ReportText & "UTI: " & ftype & return
		set ReportText to ReportText & "Default Application: " & defApp & return
		
		set ReportText to ReportText & "Size: " & item_size & return
		set ReportText to ReportText & "Version: " & item_version & return
		set ReportText to ReportText & "Alias: " & alias_indicator & return
		set ReportText to ReportText & "Cdate: " & item_creation_date & return
		set ReportText to ReportText & "Mdate: " & item_modification_date & return
		set ReportText to ReportText & "Owner: " & item_owner & return
		set ReportText to ReportText & "Owner Privileges: " & item_ownerP & return
		set ReportText to ReportText & "Group: " & item_group & return
		set ReportText to ReportText & "Group Privileges: " & item_groupP & return
		set ReportText to ReportText & "Everybodys Privileges: " & item_everyonesP & return
		set ReportText to ReportText & "Locked: " & locked_indicator & return
		if outputType is "Dialogs" then
			if this_item is the last_item then
				set the button_list to {"Done"}
			else
				set the button_list to {"Cancel", "Next"}
			end if
			-- display the information
			with timeout of 900 seconds
				tell me
					activate
					
					display dialog ReportText buttons the button_list default button (the last item of the button_list)
				end tell
			end timeout
		end if
	end repeat
	if outputType is "Report" then
		tell application "TextEdit"
			activate
			make new document at the front
			set text of front document to "F i l e   i n f o r m a t i o n " & return & ReportText
		end tell
	end if
on error e number n
	display dialog "error : " & e & n
end try

Change uti’s in Subtree
New version
If you choose two files in finder with the one with the default app to open it with set, so that that file has the newest modification date, then this script will change all files with the same extension or kind in a subtree, - the folder you choose and any subfolders within. -To open with that default app. :slight_smile:


property McUsr : "1.0 Maybe add some help or such"
set fileExt to ""
set resRec to divergingProperties(a reference to fileExt)
if resRec is not null then
	
	set theRootOfTheTree to (choose folder with prompt "Choose a tree to change \"uti's\" within") as text
	changeAllUtis(theRootOfTheTree, resRec, fileExt)
end if


on divergingProperties(fileExt)
	local theSel, propCount, fileNmA, fileNmB, fPropsA, fPropsB, dateA, dateB, newFProps, oldFProps, changeRec
	set propCount to 0
	tell application "Finder"
		set theSel to (get its selection) as alias list
		if (count of theSel) is not 2 then
			display dialog "Needs two files with same extension, where one of them is configured to be opened with another app"
			-- rework som logic here 
			error number -128
		end if
		
		set fileNmA to item 1 of theSel as text
		set fileNmB to item 2 of theSel as text
		repeat with i from 1 to 2
			if extension hidden of item i of theSel is true then set extension hidden of item i of theSel to false
		end repeat
	end tell
	tell application "System Events"
		set fPropsA to (get properties of item fileNmA)
		set contents of fileExt to (name extension of fPropsA)
		set fPropsB to (get properties of item fileNmB)
		if not (name extension of fPropsA is equal to name extension of fPropsB) then
			tell me
				activate
				display dialog "Needs two files with same extension, or of the same type where the two differs in the choice of default app to be opened with."
			end tell
			error number -128
			-- utvide til å gå på type her:
		else
			-- choose which file you want to change all the uti's too.
			
			
			set dateA to modification date of fPropsA
			set dateB to modification date of fPropsB
			if dateB > dateA then
				set newFProps to fPropsB
				set oldFProps to fPropsA
			else
				set newFProps to fPropsA
				set oldFProps to fPropsB
			end if
			-- eventually changing attributes in order of appearance 
			if not (file type of newFProps is equal to file type of oldFProps) then
				set propCount to propCount + 1
				set changeRec to {file type:(file type of newFProps)}
			end if
			
			-- so we are basically clear about what from what properties the uti data will be set.
			if not (kind of newFProps is equal to kind of oldFProps) then
				set changeRec to {kind:(kind of newFProps)}
				if propCount > 0 then
					set changeRec to changeRec & {kind:(kind of newFProps)}
				else
					set changeRec to {kind:(kind of newFProps)}
				end if
				set propCount to propCount + 1
			end if
			if not (creator type of newFProps is equal to creator type of oldFProps) then
				if propCount > 0 then
					set changeRec to changeRec & {creator type:(creator type of newFProps)}
				else
					set changeRec to {creator type:(creator type of newFProps)}
				end if
				set propCount to propCount + 1
			end if
			if not (type identifier of newFProps is equal to type identifier of oldFProps) then
				if propCount > 0 then
					set changeRec to changeRec & {type identifier:(type identifier of newFProps)}
				else
					set changeRec to {type identifier:(type identifier of newFProps)}
				end if
				set propCount to propCount + 1
			end if
			if not (default application of newFProps is equal to default application of oldFProps) then
				if propCount > 0 then
					set changeRec to changeRec & {default application:default application of newFProps} -- problem her
				else
					set changeRec to {default application:(default application of newFProps)}
				end if
				set propCount to propCount + 1
			end if
		end if
	end tell
	if propCount > 1 then -- let the show begin
		-- changeUtiForFileOLD(fileNmB, changeRec)
		return changeRec
	else
		return null
	end if
end divergingProperties

on changeUtiForFile(theFile, theChanges)
	local changedProperty
	log " thefile : " & theFile
	tell application "System Events"
		try
			set changedProperty to file type of theChanges
			-- set file type of file theFile to changedProperty
			set properties of file theFile to {file type:changedProperty}
		on error
			-- goof
		end try
		try
			set changedProperty to kind of theChanges
			-- set kind of file theFile to changedProperty
			set properties of file theFile to {kind:changedProperty}
		on error
			-- goof
		end try
		try
			set changedProperty to creator type of theChanges
			-- set creator type of file theFile to changedProperty
			set properties of file theFile to {creator type:changedProperty}
		on error
			-- goof
			
		end try
		try
			set changedProperty to type identifier of theChanges
			-- set type identifier of file theFile to changedProperty
			set properties of file theFile to {type identifier:changedProperty}
		on error
			-- goof
			
		end try
		try
			set changedProperty to default application of theChanges
			-- set default application of file theFile to changedProperty
			set properties of file theFile to {default application:changedProperty}
		on error
			-- goof
		end try
	end tell
end changeUtiForFile


on changeAllUtis(theRootOfTheTree, theChangeRec, theFileExt)
	local fileText
	tell application "Finder"
		set tSelectedFiles to (every file of folder theRootOfTheTree whose extension hidden is true)
		repeat with aFile in tSelectedFiles
			set extension hidden of aFile to false
		end repeat
		-- copy or move over files of the specified type(s)
		set tSelectedFiles to (every file of folder theRootOfTheTree whose name extension is equal to theFileExt) as alias list
		if tSelectedFiles ≠ {} then
			repeat with aFile in tSelectedFiles
				set fileText to aFile as text
				my changeUtiForFile(fileText, theChangeRec)
			end repeat
		end if
		-- copy over the folders, calling this handler recursively
		set tFolders to (every folder of folder theRootOfTheTree)
		repeat with tThisFolder in tFolders
			my changeAllUtis(tThisFolder as alias, theChangeRec, theFileExt)
		end repeat
	end tell
end changeAllUtis