applescript not detecting .dat extensions...

i’m completely frazzled on this one. i have a very simple applescript that changes the name extension of files on my desktop that have a .dat extension to a .csv. The script worked fine for months until this morning it stopped working. looked into it and there’s nothing wrong that i can see.

set thePath to path to desktop
set ext to "dat"
set extNew to "csv"

tell application "Finder" to set name extension of (files of thePath whose name extension is ext) to extNew

when i run that, i get:

the really weird thing is that if i swap it, so that it changes from .csv to .dat, it works just fine. uuugghhh, what is going on here??

Model: iMac
AppleScript: 2.6.1
Browser: Chrome 43.0.2357.130
Operating System: Mac OS X (10.9)

ok, did more testing with a different script just to see if it was recognizing it

set thisLocation to POSIX path of (path to desktop)

tell application "Finder"
	
	set myFileNames to name of files of folder (thisLocation as POSIX file) whose name extension is "dat"
	
end tell

and i keep getting:

but when i change the file on the desktop to any other extension (i’ve tried csv, xlsx, pdf, jpg, and many more) it pulls it with ZERO problems. so, my system suddenly stopped recognizing dat as a file extension???

Hi,

on my machine (Yosemite) the script works.

The path to the current desktop folder is the “root” folder of the Finder and there is a appropriate property.


tell application "Finder"
   set myFileNames to name of files of desktop whose name extension is "dat"
end tell

or even


tell application "Finder"
   set myFileNames to name of files whose name extension is "dat"
end tell

not for me. when i run your script i get:

only thing i can figure is that something on my system took control of .dat files and suddenly finder doesn’t even recognize them. this is some weird s@#$

in Finder select a .dat file and press ⌘I. Maybe there is a hidden extension

nope

Hello.

Have you tried to use diskutil to repair and check permissions?

I also wonder if you have you set any acl’s?

Having files open in other apps shouldn’t cause problems, but if any such app, isn’t a regular Cocoa app that uses NSDocument, I believe it might cause problems, at least if the file is open.

i have repaired disk permissions and reboot also. still the same problem. and no, no application is opening the file, in fact, there’s no application on my computer that is capable of opening it. that’s why i change the extension to csv. i also tried changing permissions on the file to full read and write for everyone in case that might have been an issue, but no go with that either.

how would i check on the ACL thing though?

nevermind, i found it. it’s full access

Hello.

You may want to try to “cat” the file in a terminal window, and see if it opens there.

You may also want to check any extended attributes (“ls -@”) when you are in the terminal window.

Hopefully, you have a backup on TimeMachine, if it turns out that the file is corrupted. :confused:

Edit

Are you a member of the group admin? -You check that too in the Terminal window by issuing: groups .
If not, then you should change the group to one you are a member of, if you aren’t an administrative user at all times.

cat reads it just fine in terminal. and when i run the ls, nothing unusual shows up. and yes, i’m an admin.

What’s the result of this, it displays the name extension of all files of desktop


tell application "Finder" to set myFileExtensions to name extension of files of desktop
set {TID, text item delimiters} to {text item delimiters, return}
set myFileExtensions to myFileExtensions as text
set text item delimiters to TID
display dialog myFileExtensions

i have 3 files on my desktop. one is the dat file, then two of the applescripts that i was working on. it catches the scripts, but not the dat. well, it catches a file there (notice blank line) but not the extension

Hello.

Maybe there is an invisible character along with the dot (.) please try to delete the fileextension, in the file info window of it in Finder. and then try to re-enter it.

I guess, the name extension is empty if no application is associated in launch services to open the file
Try this workaround:


set ext to ".dat"
set extNew to "csv"

tell application "Finder" to set name extension of (files of desktop whose name ends with ext) to extNew

hmmm…that kind of worked. it resulted with the file being named: ADET_AAC0001_0623.dat.csv

then it’s impossible with an one-liner


set ext to ".dat"
set extNew to "csv"

tell application "Finder"
	set filesToRename to files of desktop whose name ends with ext
	repeat with aFile in filesToRename
		set fileName to name of aFile
		set name of aFile to text 1 thru -4 of fileName & extNew
	end repeat
end tell

that worked. thank you!!