9 Replies Latest reply on Jul 17, 2017 7:41 AM by tpk1982

    Delete preset using Applescript

    tpk1982 Level 4

      Hi,

       

      I am new to Applescript. I need to delete the export preset in the local desk. The below coding is working well only when I give the user name directly. But the system may be used for many users. So how can I give the current usernames?

       

       

      tell application "System Events"
        set currentUser to (name of current user)
        delete (alias file ("/Users/" & currentUser & "/Library/Application Support/Adobe/Adobe PDF/Settings/Adobe PDF Preset 1.joboptions"))
      end tell
      

       

       

      Thanks,

      K

        • 1. Re: Delete preset using Applescript
          Dirk Becker Level 4

          How about this:

           

          tell application "Finder"
               set jo to a reference to file "test.joboptions" of folder "Settings" of folder "Adobe PDF" of folder "Adobe" of folder (path to application support folder from user domain)
               if exists jo then delete jo
          end tell
          
          1 person found this helpful
          • 2. Re: Delete preset using Applescript
            tpk1982 Level 4

            Hello Dirk,

             

            Thanks for your script. I am out of system now. Will check and let you know.

             

            Regards,

            K

            • 3. Re: Delete preset using Applescript
              tpk1982 Level 4

              Hello Dirk,

               

              Awesome... it is working as expected. After deletion is it possible to alert the user for the deletion? If it is not available then how can I alert the user the joboptions is not exist?

               

              I googled but not found

               

              Regards,

              K

              • 4. Re: Delete preset using Applescript
                tpk1982 Level 4

                The below code I tried..

                 

                 

                tell application "Finder"
                  set jo to a reference to file "test.joboptions" of folder "Settings" of folder "Adobe PDF" of folder "Adobe" of folder (path to application support folder from user domain)
                  try
                  if exists jo then delete jo
                  display dialog "Found file and deleted"
                  on error
                  display dialog "file not found"
                  end try
                end tell
                
                • 5. Re: Delete preset using Applescript
                  Dirk Becker Level 4
                  tell application "Finder"
                    set jo to a reference to file "test.joboptions" of folder "Settings" of folder "Adobe PDF" of folder "Adobe" of folder (path to application support folder from user domain)
                    if exists jo then
                    delete jo
                    display dialog "File found and deleted"
                    else
                    display dialog "File not found"
                    end if
                  end tell
                  
                  1 person found this helpful
                  • 6. Re: Delete preset using Applescript
                    tpk1982 Level 4

                    Hello Dirk,

                     

                    Working like a charm.. I tried the above coding previously but the third line as

                     

                    if exists jo then delete jo
                    

                     

                    So that it throw error.. thanks for the revised code..

                     

                    Not sure I am asking too many questions, but if possible please suggest me.

                     

                    How to clear Caches files from user?

                     

                    tell application "Finder"
                      delete (get items of folder (path to caches folder from user domain))
                      empty trash
                      say "items deleted"
                    end tell
                    

                     

                    Thanks,

                    Karthi

                    • 7. Re: Delete preset using Applescript
                      Dirk Becker Level 4

                      Karthi,

                      as there apparently is no key phrase "caches folder", you have to start from the library folder.

                      Anyway I think deleting all caches is a bad idea, some might be in use by open programs.

                       

                      tell application "Finder"

                        get name of every item of folder "Caches" of folder (path to library folder from user domain)

                      end tell

                      1 person found this helpful
                      • 8. Re: Delete preset using Applescript
                        tpk1982 Level 4

                        Hi Dirk,

                         

                        My idea is saving the script as application and run by login items in user & groups. So every time the user logged in, the script will run automatically and clear the caches.

                         

                        May I know how to delete that? The above script will give the names of cache folder. Something like

                         

                         

                        tell application "Finder"
                          delete (get every item of folder "Caches" of folder (path to library folder from user domain))
                          
                          say "Caches deleted"
                        end tell
                        

                         

                        Thanks,

                        Karthi

                        • 9. Re: Delete preset using Applescript
                          tpk1982 Level 4

                          Hi Dirk,

                           

                          My idea is saving the script as application and run by login items in user & groups. So every time the user logged in, the script will run automatically and clear the caches.

                           

                          May I know how to delete that? The above script will give the names of cache folder. Something like

                           

                          tell application "Finder"  
                            delete (get every item of folder "Caches" of folder (path to library folder from user domain))  
                              
                            say "Caches deleted"  
                          end tell 
                          

                           

                          Thanks,

                          Karthi