Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Delete preset using Applescript

Guide ,
Jul 14, 2017 Jul 14, 2017

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

TOPICS
Scripting
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Jul 14, 2017 Jul 14, 2017

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

Translate
Mentor ,
Jul 14, 2017 Jul 14, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 14, 2017 Jul 14, 2017

Hello Dirk,

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

Regards,

K

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 16, 2017 Jul 16, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 16, 2017 Jul 16, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 17, 2017 Jul 17, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 17, 2017 Jul 17, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 17, 2017 Jul 17, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 17, 2017 Jul 17, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 17, 2017 Jul 17, 2017
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines