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

AppleScript - File Rename and move to OUT Path

Enthusiast ,
Oct 21, 2020 Oct 21, 2020

Copy link to clipboard

Copied

HI All,

I need a help for the below request.

 

1. User has to place the files in the "IN" Folder like "test.txt"

2. AppleScript want to move to "OUT" Folder with rename of "err_text.txt"

 

For your better understanding,

 

Screenshot 2020-10-21 at 7.19.16 PM.png

 

Thanks

SS

TOPICS
Scripting

Views

1.0K

Translate

Translate

Report

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
Community Expert ,
Oct 21, 2020 Oct 21, 2020

Copy link to clipboard

Copied

You would use the Finder to move the file and rename it:

 

tell application "Finder"
	--the path to the file to move
	set dt to path to desktop
	set mf to dt & "Test:IN:test.txt" as string
	
	--the move file’s name
	set fn to name of file mf
	
	--the destination folder
	set df to dt & "Test:OUT:" as string
	
	--move the file to the destination folder
	set ef to move file mf to folder df
	
	--change the moved file‘s name
	set name of ef to "err_" & fn
end tell

Votes

Translate

Translate

Report

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
Advocate ,
Oct 21, 2020 Oct 21, 2020

Copy link to clipboard

Copied

LATEST

Try this code snippet:

tell application "Finder"
   set theFile to file "test.txt"
   set oldDelims to AppleScript's text item delimiters
   set AppleScript's text item delimiters to {"."}
   try
       set fileName to name of theFile
       set nameWithoutExtension to first text item of fileName
       set name of theFile to "err_test.txt"
       set AppleScript's text item delimiters to oldDelims
       move POSIX file "/Users/xx/In/err_test.txt" to POSIX file "/Users/xx/Out/" with replacing
   on error
       set AppleScript's text item delimiters to oldDelims
   end try
end tell

Best

Sunil

Votes

Translate

Translate

Report

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