Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
Apple Computing Products:
macOS - Operating System
How can I rename a file with a drag and drop process, using a list as my source data?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="MacGrunt" data-source="post: 1392712" data-attributes="member: 210105"><p><strong>G'day again</strong></p><p></p><p>Sorry, I missed the bit about how you don't have Excel.</p><p></p><p>OK, if you're able to export the list as a .csv (comma delimited) file then you could do something like this :</p><p></p><p>[CODE]set mgOriginalNames to {}</p><p>set mgNewNames to {}</p><p></p><p>tell application "Finder"</p><p> set mgTheList to "Colon:Delimited:Path:ToYour:ListFile.csv" as alias</p><p> set mgFolderPath to "Colon:Delimited:Path:ToYour:Folder:" as alias</p><p>end tell</p><p></p><p>open for access mgTheList</p><p>set mgList to (read mgTheList)</p><p>close access mgTheList</p><p></p><p>tell application "Finder"</p><p> -- split original list into two lists</p><p> set text item delimiters of AppleScript to ","</p><p> repeat with x from 1 to count paragraphs of mgList</p><p> set end of mgOriginalNames to text item 1 of paragraph x of mgList</p><p> set end of mgNewNames to text item 2 of paragraph x of mgList</p><p> end repeat</p><p> set text item delimiters of AppleScript to ""</p><p> -- get the folder items</p><p> tell application "Finder"</p><p> set mgItems to items of (mgFolderPath as alias)</p><p> end tell</p><p> -- check name and rename if match is found</p><p> repeat with mgItem in mgItems</p><p> set mgName to name of mgItem</p><p> set mgExt to name extension of mgItem</p><p> if mgExt is not "" then set mgExt to "." & mgExt</p><p> set text item delimiters of AppleScript to {"."}</p><p> set mgOldName to text item 1 of mgName</p><p> set text item delimiters of AppleScript to ""</p><p> repeat with x from 1 to count items in mgOriginalNames</p><p> if mgOldName = item x of mgOriginalNames then</p><p> set mgNewName to item x of mgOriginalNames & "_" & item x of mgNewNames</p><p> tell application "Finder"</p><p> set name of mgItem to (mgNewName & mgExt)</p><p> end tell</p><p> end if</p><p> end repeat</p><p> end repeat</p><p>end tell[/CODE]</p><p></p><p>If you can only use a .txt file, you'll have to know <em>exactly</em> how many spaces between entries ('about 5' won't help you). Then relace the comma in this line — <strong>set text item delimiters of AppleScript to ","</strong> — with that number of spaces</p><p></p><p>At the top of that script there's a place for you to enter a "Colon<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big grin :D" loading="lazy" data-shortname=":D" />elimited<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick out tongue :p" loading="lazy" data-shortname=":p" />ath:To... " for the list file and the folder containing the files to rename. The easiest way to get this path is to have the file or folder selected in the Finder and then run this script from Script Editor :</p><p>[CODE]tell application "Finder"</p><p> get selection as alias</p><p>end tell[/CODE]</p><p>Then just copy and paste the quoted path from the <em>Result</em> window into the appropriate place in the main script.</p><p></p><p>Note that the script in its current form doesn't have any sort of filter to only deal with .mov files — it will rename any files or folders stored in that folder you specify.</p><p></p><p>To change the all caps to lower case you could run the whole lot through the <em>Rename Finder Items</em> action in Automator.</p><p></p><p>Hope that helps</p><p></p><p><strong>m.</strong></p></blockquote><p></p>
[QUOTE="MacGrunt, post: 1392712, member: 210105"] [B]G'day again[/B] Sorry, I missed the bit about how you don't have Excel. OK, if you're able to export the list as a .csv (comma delimited) file then you could do something like this : [CODE]set mgOriginalNames to {} set mgNewNames to {} tell application "Finder" set mgTheList to "Colon:Delimited:Path:ToYour:ListFile.csv" as alias set mgFolderPath to "Colon:Delimited:Path:ToYour:Folder:" as alias end tell open for access mgTheList set mgList to (read mgTheList) close access mgTheList tell application "Finder" -- split original list into two lists set text item delimiters of AppleScript to "," repeat with x from 1 to count paragraphs of mgList set end of mgOriginalNames to text item 1 of paragraph x of mgList set end of mgNewNames to text item 2 of paragraph x of mgList end repeat set text item delimiters of AppleScript to "" -- get the folder items tell application "Finder" set mgItems to items of (mgFolderPath as alias) end tell -- check name and rename if match is found repeat with mgItem in mgItems set mgName to name of mgItem set mgExt to name extension of mgItem if mgExt is not "" then set mgExt to "." & mgExt set text item delimiters of AppleScript to {"."} set mgOldName to text item 1 of mgName set text item delimiters of AppleScript to "" repeat with x from 1 to count items in mgOriginalNames if mgOldName = item x of mgOriginalNames then set mgNewName to item x of mgOriginalNames & "_" & item x of mgNewNames tell application "Finder" set name of mgItem to (mgNewName & mgExt) end tell end if end repeat end repeat end tell[/CODE] If you can only use a .txt file, you'll have to know [I]exactly[/I] how many spaces between entries ('about 5' won't help you). Then relace the comma in this line — [B]set text item delimiters of AppleScript to ","[/B] — with that number of spaces At the top of that script there's a place for you to enter a "Colon:Delimited:Path:To... " for the list file and the folder containing the files to rename. The easiest way to get this path is to have the file or folder selected in the Finder and then run this script from Script Editor : [CODE]tell application "Finder" get selection as alias end tell[/CODE] Then just copy and paste the quoted path from the [I]Result[/I] window into the appropriate place in the main script. Note that the script in its current form doesn't have any sort of filter to only deal with .mov files — it will rename any files or folders stored in that folder you specify. To change the all caps to lower case you could run the whole lot through the [I]Rename Finder Items[/I] action in Automator. Hope that helps [B]m.[/B] [/QUOTE]
Verification
Name this item 🌈
Post reply
Forums
Apple Computing Products:
macOS - Operating System
How can I rename a file with a drag and drop process, using a list as my source data?
Top