Move files and create unique name something wrong with my script

Can you see where I might be going wrong here?
Just trying to create a unique name if something exists.
In English.
Move file to the destinationFolder
Item exists in destinationFolder > Move file in the destination folder to the fake Trash > If it exists in fakeTrash too then give it a new name an ending of_a.psd then out it in the trash
Once thats done move start file to the destination folder.
Currently when the file exists in the destination folder and in the trash, I get the prompt then the error
error "System Events got an error: Can’t get disk item \"NN_FR10WW06290PK3LE.psd\"." number -1728 from disk item "NN_FR10WW06290PK3LE.psd"
set fileMatrix to {¬
          {folderName:"BHS", prefixes:{"BH", "SM", "AL"}}, ¬
          {folderName:"Bu", prefixes:{"BU"}}, ¬
          {folderName:"Da", prefixes:{"ES"}}, ¬
          {folderName:"Di", prefixes:{"DV"}}, ¬
          {folderName:"Do", prefixes:{"DJ", "RA"}}, ¬
          {folderName:"In", prefixes:{"GT", "CC"}}, ¬
          {folderName:"Fr", prefixes:{"FR"}}, ¬
          {folderName:"No", prefixes:{"NN"}}, ¬
          {folderName:"Ma", prefixes:{"MA", "MF", "FI", "MC", "MH", "MB"}}, ¬
          {folderName:"Pr", prefixes:{"PR"}}, ¬
          {folderName:"To", prefixes:{"TM15", "TM11", "TM17"}}, ¬
          {folderName:"Wa", prefixes:{"WA"}}, ¬
          {folderName:"Se", prefixes:{"SE"}}}
tell application "Finder"
          set theHotFolder to folder "Hal 9000:Users:matthew:Pictures:HotFolderDone"
          set foldericon to folder "Hal 9000:Users:matthew:Pictures:Icons:Rejected Folder Done"
          set fakeTrash to folder "Hal 9000:Users:matthew:FakeTrash"
  ---here
          repeat with matrixItem in fileMatrix -- look for folder
                    set destinationFolder to (folders of desktop whose name starts with folderName of matrixItem)
                    if destinationFolder is not {} then -- found one
                              set destinationFolder to first item of destinationFolder -- only one destination
                              set theFolderName to name of destinationFolder
                              repeat with aPrefix in prefixes of matrixItem -- look for files
                                        set theFiles to (files of theHotFolder whose namestarts with aPrefix) as alias list
                                        if theFiles is not {} then repeat with startFile intheFiles -- move files
                                                  try
  move startFile to destinationFolder
                                                  on error
  activate
                                                            display dialog "File “" & (name ofstartFile) & "” already exists in folder “" & theFolderName & "”. Do you want to replace it?"buttons {"Don't replace", "Replace"} default button 2 with icon 1
                                                            if button returned of result is "Stop"then
                                                                      if (count theLastFolder) is 0 thendelete theLastFolder
                                                                      return
                                                            else if button returned of result is"Replace" then
                                                                      set fileName to get name ofstartFile
                                                                      if exists file fileName indestinationFolder then ¬
                                                                                try
  --next line moves existing file to the faketrash
  move file fileName of destinationFolder to fakeTrash
  move file startFile to destinationFolder
  --if it already exists in fake trash give it a new name then move that file to fake trash
                                                                                on error errmess numbererrnum -- oops (should probably check for a specific error number)
                                                                                           log "Error " & errnum& " moving file: " &errmess
                                                                                           set newName to mygetUniqueName(fileName,fakeTrash)
                                                                                           set name of fileNameto "this is a unique name"-- or whatever
                                                                                           set name of fileNameto newName
  --Now move the renamed file to the fake trash
  move file fileName to fakeTrash
  --now move the startfile to destination folder
  move file startFile to destinationFolder
                                                                                end try
                                                            else -- "Don't replace"
                                                                      if not (exists folder "Hal 9000:Users:matthew:Desktop:Rejected Folder Done") then
                                                                                set theLastFolder toduplicate foldericonto desktop
                                                                      else
                                                                                set theLastFolder to folder"Hal 9000:Users:matthew:Desktop:Rejected Folder Done"
                                                                      end if
                                                                      delay 0.5
  move startFile to theLastFolder with replacing
                                                            end if
                                                  end try
                                        end repeat
                              end repeat
                    end if
          end repeat
          try
                    if (count theLastFolder) is 0 then delete theLastFolder
          end try
end tell
to getUniqueName(someFile, someFolder)
     check if someFile exists in someFolder, creating a new unique file name (if needed) by adding a suffix
          parameters -          someFile [mixed]: a source file path
                              someFolder [mixed]: a folder to check
          returns [list]:          a unique file name and extension
          set {counter, suffixes, divider} to {0, "abcdefghijklmnopqrstuvwxyz", "_"}
          set someFile to someFile as text -- System Events will use both Finder and POSIX text
          tell application "System Events" to tell disk item someFile to set{theName, theExtension} to {name, name extension}
          if theExtension is not "" then set theExtension to "." & theExtension
          set theName to text 1 thru -((length of theExtension) + 1) of theName -- just the name part
          set newName to theName & theExtension
          tell application "System Events" to tell (get name of files of folder(someFolder as text))
                    repeat while it contains newName
                              set counter to counter + 1 -- hopefully there aren't more than 26 duplicates (numbers are easier)
                              set newName to theName & divider & (item counter ofsuffixes) & theExtension
                    end repeat
          end tell
          return newName
end getUniqueName

There are numerous errors in your script, and it's a large script so there might be more, but these are the standouts for me:
At line 48 you:
                                                                      set fileName to get name of startFile
which is fair enough - you then use this to see if the file already exists in the destinationFolder. However, if it does the logic about how to deal with that is flawed.
At line 56 you catch the error:
                                                                                on error errmess number errnum -- oops (should probably check for a specific error number)
                                                                                          log "Error " & errnum & " moving file: " & errmess
                                                                                          set newName to my getUniqueName(fileName, fakeTrash)
                                                                                          set name of fileName to "this is a unique name" -- or whatever
                                                                                          set name of fileName to newName
  --Now move the renamed file to the fake trash
  move file fileName to fakeTrash
  --now move the startfile to destination folder
  move file startFile to destinationFolder
                                                                                end try
so let's focus on that.
56: catch the error
57: log the error
58: generate a new unique filename
59: change the name of fileName to some other string
Hang on, wait a minute.... we already ascertained that at line 48 you defined fileName as a string object that indicates the name of the file. This is just a string. It's no longer associated with the original file... it's just a list of characters. Consequently you cannot set the 'name' of a string, hence your script is doomed to fail.
Instead, what I think you want to do is set the name of the startFile to the unique string. Files have filenames, and therefore you can set the name.
You have a similar problem on line 64 where you try to 'move file filename to fakeTrash'. fileName is just a string of characters. It isn't enough to identify a file - let's say the file name is 'some.psd'. You're asking AppleScript to move file some.psd to the trash. The question is which some.psd? The one on the desktop? in your home directory? maybe on the root of the volume? or maybe it should search your drive to find any/all files with that name? nope. None of the above. You can't just reference a file by name without identifying where that file is. So you probably want to 'move file fileName of destinationFolder...'
There may be other problems, but they're likely to be related - all issues with object classes (e.g. files vs. strings), or not being specific about which object you want.
As I said before, though, I might be way off - you don't say where the error is triggered to make it easy to narrow down the problem. Usually AppleScript will highlight the line that triggered an error. Knowing what that line is would help a lot.

Similar Messages

  • How do I use a usb portable drive to let me add or move files and create folders

    I have a 256 gb porable smart drive  USB and need to move some files to another USB 1 TB drive and create a folder on the 1 TB drive for the data off of the smaller one.  When I try to create a folder and using finder it has the new folder grayed out.  using Info it tells me that I only have permission to read the drives but they both worked fine on the windows Laptop.  I guess I need to learn more about Finder.

    I guess you're trying to create the folder on the 1TB drive.
    Question: Are you OK initializing that drive on your Mac?
    If so, you can use Disk Utility (in Applications > Utilities) to do so.

  • Published a Mov File and I get a Quicktime Symbol with a ? What can i do?

    I published a site with iWeb with a .Mov file in it about 20 seconds long. When it finished publishing, i checked out the website and instead of the video playing, i see a QUICKTIME symbol with a (?) question mark on it. what can i do to make this work. should i format the .Mov file to avi, mpeg-4 or another? help me guys, pls. thanks.

    It's not an iWeb issue. Rather a QuickTime one.
    Your original movie is 29,1MB (rather large for 20 seconds) and 960x540 pixels and Apple Intermediate Codec.
    It is displayed on your webpage as 772x450 (not proportionally).
    When I scale it to 800x450 (proportionally) and export it to QuickTime as h.264 and Faststart it only is 709kB.
    About 1/40th. And hardly any noticeable loss of quality.
    Lately there's an influx of videoprofessionals who have difficulty putting their movies on the web. Perhaps some masterclasses would be in order.
    I'm not a professional, but I think I know a trick or two:
    http://www.wyodor.net/iFrame/
    I use QuickTime Pro, iMovie and my [poor mans's RED|http://www.theflip.com].
    Message was edited by: Wyodor

  • I have about 120 apps and there hasnt been an update on any of the, I have about 120 apps and there hasn't been an update on any of the apps in about a week. All the apps are from the top paid and free. Is something wrong with my iPod?

    Help please

    Nope, it either needs to be plugged in or turned on with the power button.
    A replacement iPhone 4 is $149, but at least the whole phone is replaced.

  • How to crop a mp3 file and create a new small one from it?

    Hi all,
    I would crop a long mp3 sound file and create a new small one with the short part from the long mp3 sound file. How to do it? Anybody can help me?
    Thank you very much.
    Regard
    David

    Have you managed to do this?
    I would also like to know how.
    Thanks
    Jeff Singer

  • In Quicktime Pro I try to create a mov file and I get an error "-43 a file could not be found".  Any ideas?

    In Quicktime Pro I try to create a mov file and I get an error "-43 a file could not be found".  Any ideas?

    I have a similar problem which i did not have before...and it exists only in some powerpoint files which i want to print as a pdf file...and i get the same message as above.
    the log says the bellow details...what's the problem and how can i resolve it? thanks.
    %%[ ProductName: Distiller ]%%
    %%[Page: 1]%%
    %%[Page: 2]%%
    Cambria not found, using Courier.
    %%[ Error: invalidfont; OffendingCommand: show ]%%
    Stack:
      %%[ Flushing: rest of job (to end-of-file) will be ignored ]%%

  • When trying to move file and use command and drag, it doesn't move the file just creates a short cut.

    When trying to move file and use command and drag, it doesn't move the file just creates a short cut.

    Using command creates a copy.
    If you want to just move a file, click on it, hold it and drag it to the new location.

  • I have a Mid 2009 Macbook Pro 13 with no restore disk; it has OS 10.8.4 I believe there is something wrong with the OS due to I can not install flash player to view Youtube videos and the when we plug in a Bose headset the sound out will work sometimes

    I bough a used Macbook Pro mid 2009 that came with OS 10.8.9 it didn't have a backup restore disk with S/N W8******66D
    When trying to view some youtube videos; a window would pop up saying "it needs adobe flash player is required for video play back get the latest flash player" but after downloading the file and during installation would have errors and will not installed.....tried to reboot and install again.....but still the same.
    The othe thing I had noticed is when using a good Bose headset with mic the sound output would noticed the headset and then switch from headset to Internal speekers and headset.....thinking that there might be something wrong with the plug in port of the computer or the headset.....the headset works with no issues on my iPad so there must be something wrong with the computer.....tried to move the plugin around the port but no change....while the headset is plug in can hear a short clicking noise and the sound would get lost and back again......but with nothing plugin to the port there is no issue with the sound or mic.
    Thanks for your feed back......it looks like I have two different issues one is a software issue and the outher is a hardware issue
    <Edited By Host>

    The "restore disk" is built into the Mac. See About Recovery.
    Need more specifics about what error messages you got while installing Adobe Flash.
    However, you can almost avoid Flash altogether by setting YouTube to play the HTML5 version instead.
    Click the Try something new! link at the bottom of the YouTube page.
    I don't know about the sound issue. Might be hardware as you think. Try other headphones to check.

  • Is there something wrong with Quicktime and TIFFs?

    I've been trying to see with Firefox the TIFF images of patents at the USPTO site and I can't. The browser advises me to install the missing plug-in although Quicktime is already installed. I wonder if it's a Quicktime problem or a Firefox one. I have a reason to believe there's something wrong with Quicktime though. Read on to see why.
    On my system the *TIFF Image Test* (from mozdev.org) fails although I have the latest Quicktime plug-in. This happens regardless of the browser I use, all latest editions: Firefox 3.6, Internet Explorer 8 (both 32-bit and 64-bit versions) and Chrome 4. All seem to fail to recognize the presence of the installed Quicktime although my Windows OS is set to open TIF/TIFF files with Quicktime/PictureViewer.
    Running about:plugins on my Firefox does show the Quicktime plug-in for a variety of files but NOT for opening embedded TIF/TIFFs. Also, when I open *Tools -> Options -> Applications* I see there is no registered handler for TIF/TIFFs. They don't appear on the known Content Types.
    Is there something wrong with the installation of Quicktime? I can see USPTO TIFF images only with Safari which appears to have an integrated TIFF viewer. I haven't tried to install alternatiff or any other alternative TIFF handler.

    DocBAZ,
    I tried to visit the "test site" above. I'm not really sure it's an embedded image on a HTML page because I get a Firefox download window and a suggestion to open it with PictureViewer, which is the expected behavior for downloadable images. The mozdev.org test page on the other hand had an embedded image that needed the plugin, which is what is bugging me.
    If you want a real complex test page with both an embedded TIFF and a downloadable one check AlternaTIFF here: http://www.alternatiff.com/testpage.html
    Indeed the changes I made were in the QuickTime preferences, not PictureViewer which has no settings to change. And yes, Windows 7 has a unique place to deal with file types and MIME settings.
    You will find some interesting suggestions over the problem at SuperUser.
    http://superuser.com/questions/107142/uspto-site-asks-for-quicktime-plug-in-whic h-i-already-have-installed-why

  • Use Automator to move files and folder structure to another folder, retaining destination contents

    I have been struggling trying to setup Automator to move files and folder structure to another folder, retaining the destination contents.  Basically, I need to add files at the destination, within the same folder structure that exists at the source.  Here's some details about the scenario:
    -I have PDF files that I create on a seperate computer than I my daily use machine
    -For security reasons, the source computer doesn't have access to any shares on the destination computer
    -The destination computer has access to shares on the source computer
    -I want to delete the original PDFs at the source after they are moved or copied
    I haven't been able to get Automator to move or copy the folder contents (files and subfolders) without dropping everything copied at the top level of the destination, resulting in many duplicate folders and a broken folder structure.
    So far I've only had luck getting this to work at the command line, but I'd really like to have this setup in Automator so that I could have either a service or application that I could use for any folder, prompting for the source and destination folders.  I'm a relatively new Mac user with limited Linux experience, so this is the command that I've cobbled together and currently accomplishes what I'm looking for:
    ditto /Volumes/SMB_Temp/SOURCE ~/Desktop/Documents/DESTINATION
    cd /Volumes/SMB_Temp/SOURCE
    find . -type f -name "*.pdf" -exec rm -f {} \;
    Thanks for any ideas!

    If you have a command-line syntax that works, why not just create an Automator workflow with a single 'Utilities -> Run Shell Script' action, where that action has your (working) shell commands?
    Seems way, way simpler to me than trying to reinvent the wheel and transcribe shell commands into individual Automator actions

  • "The file 'Acknowledgements.rtf' cannot be installed because the file cannot be found in the cabinet file 'iTunes.cab'.  Is there something wrong with the latest installer? (11.3.1)

    Getting error message as shown: "The file 'Acknowledgements.rtf' cannot be installed because the file cannot be found in the cabinet file 'iTunes.cab'.  Is there something wrong with the latest installer? (11.3.1)

    Installs fine for me, so I'd guess you got an incomplete or corrupt download. See the Further Information area of Troubleshooting issues with iTunes for Windows updates for direct links and download a fresh copy of the installer.
    tt2

  • I just purchased Final Cut Pro X and I want to burn a dvd but the tabs do not see the option of SHARE. Is there something wrong with my Final Cut Pro X?

    I just purchased Final Cut Pro X and I want to burn a dvd but the tabs do not see the option of SHARE. Is there something wrong with my Final Cut Pro X?

    It's also under the File menu.

  • What is the best, most efficient way to read a .xls File and create a pipe-delimited .csv File?

    What is the best and most efficient way to read a .xls File and create a pipe-delimited .csv File?
    Thanks in advance for your review and am hopeful for a reply.
    ITBobbyP85

    You should have no trouble doing this in SSIS. Simply add a data flow with connection managers to an existing .xls file (excel connection manager) and a new .csv file (flat file). Add a source to the xls and destination to the csv, and set the destination
    csv parameter "delay validation" to true. Use an expression to define the name of the new .csv file.
    In the flat file connection manager, set the column delimiter to the pipe character.

  • Hi apple users, I am in need of your expertise. I have a mov file and mp4 file which I need converted to DVD. However IDVD quality is terrible and wondering if anyone can help!?

    Hi apple users, I am in need of your expertise. I have a mov file and mp4 file which I need converted to DVD. However IDVD quality is terrible and wondering if anyone can help!?
    I created project in iMovie then exported it to MP4 and also MOV file at highest definition possible + I added it to iDVD and had a number issues about encoding errors regarding the mp4 file. MOV worked but the quality was terrible.....
    MOV file is as follows:
    4.08GB
    Codecs: H.264, ACC
    Colour Profile: HD (1-1-1)
    Dimensions: 1920 x 1080
    Duration: 12:33
    Audio Channels: 2
    MP4 File is as follows:
    3.02GB
    Codecs: H.264, ACC
    Colour Profile: HD (1-1-1)
    Dimensions: 1280 x 720
    Duration: 12:33
    Audio Channels: 6
    I have a MacBook Pro using the Yosemite system upgrade.
    I have updated iDVD and iMovie.
    I even bought the iSkysoft app from the mac store and that was terrible too.
    PLEASE HELP i am getting desperate and about to launch this macbook into the air
    2.66 GHz Intel Core i7
    Version 10.10. 2

    First of all, Hunt--thanks for responding!
    "First, where are you playing the MPEG-2, that you see that jitter?"
    On both a MacBook Pro, an Acer laptop and my Mac Tower. I would love to think that it is a problem with the playback system, and that if I merely send the file off to the duplicator they won't have the same problem. Maybe that is the case...I don't know if I have a choice rather than sending it off to see. But it happens in the same spots, in the same way, on all three of the players so I'm a little reluctant to have faith.
    "Another thing that can cause jitter in an MPEG-2 is the Bit-Rate - higher the Bit-Rate, the better the quality, but the larger the file. For a DVD, one is limited by the total Bit-Rate (both Audio & Video), but with longer prodcutions, some users choose too low a Bit-Rate. If this is the issue, one would need to go back to the original Project and do a new Export/Share."
    Of course, but in the case there is no more 'original project.' It is gone like the wind, stolen along with his computer and backups.
    I think I am stuck using one of two files as my master: a DVD he burned where I only see the stutter/vibration/jitter once, or the mpeg2 file where I see it three times. Hopefully, the duplication house can rip if off of one of them and not see the jitter. I know that in audio, my personal filed, you can do a lot to enhance already existing sound--EQ, compression, tape saturation emulation software, etc. I guess I'm hoping there is some kind of analog to the video world that address jitter after a source has been printed--if indeed the source has been printed to be jittery.
    Thanks,
    Doug

  • Time Capsule error 22 - My time capsule was working fine and didn't notice anything wrong with it until it stopped backing up about two weeks ago. I never changed anything like computer names or the Airport settings. All I get is the following: The backup

    Time Capsule error 22 - My time capsule was working fine and didn't notice anything wrong with it until it stopped backing up about two weeks ago. I never changed anything like computer names or the Airport settings. All I get is the following:
    The backup disk image "/Volumes/Data/Linda's Computer 1.sparsebundle" could not be created (error 22).
    I tried resetting the Time Capsule and connecting with an ethernet cable, although the Ariport Utility says everything is working fine through WiFi.

    If the light will not turn on the TC is dead. No matter that the hard disk is running.. it should only run at start up or when it is accessed not constantly.. that means the board in the TC has failed. Apple do not repair them.. They will replace it under warranty or applecare.
    If you have gone over the 12month warranty it will still be covered if you have applecare on any computer or an Apple TV. In fact the cost of the apple TV plus apple care is still cheaper than buying a new TC.. so it is a route some people are taking.. certainly depends.. in some places like Europe or Australia now, there is a recognition that statutory warranty must be longer on a product that is premium to the market. 12months is not good enough. Apple will sometimes listen.
    They might be fixable but I do not know how.

Maybe you are looking for

  • Downloading videos from a disk.

    Okay so I tried downloading this video that I made on another MacBook on to my Macbook, so I put it in then the DVD player comes up and goes to full screen and I can't get out of it without ejecting the disk. So, how do I go about downloading the vid

  • How to upload selections in web report

    Hello Experts, Problem Faced: When my user is executing the query in the web. In the initial screen there is s varaible for CSO entry. He wants to upload the CSOs from the text file to speed up the process. (In BEX analyzer there is an option as uplo

  • Material Master Characteristic Configuration

    Hi Experts, I'd like to know how to configure the Material Master Maintenance MM01/MM02/MM03 tcodes to show the Characteristic Tab and all other tabs that can be activated. And also what are the configuration to consider when using the Characteristic

  • Content type of .key files

    Dear team , please tell me the "contenttype" of the .pages file format.... example: .doc....is having the content type as "application/ms-word" similarly can u tell me content type of .pages Regards, spradeepkumar

  • Slow LabView 2013

    Hi I have Labview 2013 Professional Dev Sys SP1 ver 13.0.1f2 (32-Bit) and it is slow when I develop any aplication. For example, if I have a tab control and I change to another tab, it takes about 2 seconds to change tab after I click it. If i wire a