1

I have many images that contain the "Where from" metadata in the "get info" section that shows the URL where they were downloaded from. I want to remove this information from all of them at the same time.

I created an Applescript that works when the shell script retrieves one image from the selected folder in finder. But when the shell script result is multiple images, I get the following error:

xattr: No such file:

I need the Applescript to work without the use of a handler since it will be used in an application that does not accept handlers.

tell application "Finder" to set selectedFolder to selection as alias list
set folderPath to quoted form of POSIX path of selectedFolder

set getImages to "mdfind -onlyin " & folderPath & " 'kMDItemKind = *image'"
set selectedImages to paragraphs of (do shell script getImages)

set filePaths to {}
repeat with thisFile in selectedImages
    set end of filePaths to quoted form of POSIX path of thisFile
end repeat

do shell script "xattr -d com.apple.metadata:kMDItemWhereFroms " & filePaths
1
  • Passing more than one selected folder to this workflow will cause an error on the second line. While AppleScript is reasonably savvy at dealing with a list containing a single string and, where necessary, knowing when to use the string rather than the list, it isn't able to do this with any list of two or more items. Neither POSIX path nor quoted form are properties available to a list so both are going to complain if you make them try and deal with anything besides the trivial case. – CJK Dec 24 '19 at 1:53
0

You need to add:

& space

To:

set end of filePaths to quoted form of POSIX path of thisFile

Example:

set end of filePaths to quoted form of POSIX path of thisFile & space

Another way to resolve this issue is to coerce the list filePaths to a string before it's used in the do shell script command, as after all it does get coerced in the process.

So, just before the do shell script "xattr ... command, do the following, instead of using & space as previously mentioned:

set text item delimiters to space
set filePaths to filePaths as string
set text item delimiters to ""
6
  • Wow! I can't believe it was that easy. After hours of searching all I needed to do was add "& space". Thank you so much. – David Dec 24 '19 at 0:51
  • @David, It took me longer to write up the answer then to see what was wrong with the code. :) – user3439894 Dec 24 '19 at 0:54
  • That what happens when you mix a newbie with Applescript. Simple mistakes like this happen to me all the time. I only have one month learning it so I will get better with time :-) – David Dec 24 '19 at 0:59
  • @CJK, Having a surplus whitespace dangling is not going to hurt anything in this instance. Also, off the top of my head I cannot think of one command line utility that is going to baulk about a single space character after the last argument. – user3439894 Dec 24 '19 at 1:18
  • @user3439894 It would suffice just to insert set text item delimiters to space before the do shell script line, where the coercion will occur regardless. Although, doing it explicitly as your addendum lays out makes it crystal clear what is happening. – CJK Dec 24 '19 at 1:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .