Highlighted

AppleScript - File Rename and move to OUT Path

Enthusiast ,
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

32

Likes

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

AppleScript - File Rename and move to OUT Path

Enthusiast ,
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

33

Likes

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
Oct 21, 2020 0
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Oct 21, 2020 0
Adobe Community Professional ,
Oct 21, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Oct 21, 2020 0