Thursday, September 19, 2019

#1 2019-06-13 01:03:45 pm

chrisndeca
Member
From:: Oakland, CA
Registered: 2005-06-28
Posts: 19

Finding the right syntax for renaming files with FileManagerLib

Hi all,

I am trying to figure out what the correct syntax for renaming a file using Shane's FileMangerLib.

Looking at the readme, it looks like it should be as simple as

Applescript:

set rename object theItem to (("hello") as string)

But that is probably a really gross line of code on my part.

Like I said I have looked at the readme, but there are no examples in that of using the rename command, in fact I can't seem to find a single example online. So I have come here to seek guidance.

For reference, here is the entire script:

Applescript:

use scripting additions
use theLib : script "FileManagerLib" version "2.2.1"
set folderPath to POSIX path of (choose folder with prompt "Choose a folder:")
set theFolder to POSIX file folderPath as alias
set theContents to objects of theFolder
repeat with i from 1 to (count of items of theContents)
   set theItem to item i of theContents
   set aliasItem to (POSIX file theItem) as alias
   set rename object aliasItem to (("hello" & i) as string)
end repeat

That gives me a stack overflow error when I try to run it from both Script Debugger 7 and Script Editor 2.10. I am running on 10.13.

Looking at examples for some of the other commands in FileManagerLib I realize that what I am trying to do is probably too simplistic, and the right way probably involves a bit more code.

Model: 2018 MBP 15"
Browser: Safari 605.1.15
Operating System: macOS 10.13


Filed under: rename, FileManagerLib

Offline

 

#2 2019-06-13 05:16:55 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5896

Re: Finding the right syntax for renaming files with FileManagerLib

The second parameter is named to name, so:

Applescript:

rename object theItem to name "hello"

Your full script can be simplified a bit:

Applescript:

use scripting additions
use theLib : script "FileManagerLib" version "2.2.1"

set theFolder to (choose folder with prompt "Choose a folder you don't mind mangling:")
set theContents to objects of theFolder
repeat with i from 1 to count of theContents
   rename object (item i of theContents) to name ("hello" & i)
end repeat


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2019-06-13 06:45:25 pm

chrisndeca
Member
From:: Oakland, CA
Registered: 2005-06-28
Posts: 19

Re: Finding the right syntax for renaming files with FileManagerLib

Thanks Shane. Sometimes it is the simplest things that we miss! Should have tried "name"...

Offline

 

#4 2019-06-13 09:05:00 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5896

Re: Finding the right syntax for renaming files with FileManagerLib

It really does pay to check the parameter names in the dictionary. For any app/library, they're something that's easy to get wrong.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#5 2019-06-14 11:31:18 am

chrisndeca
Member
From:: Oakland, CA
Registered: 2005-06-28
Posts: 19

Re: Finding the right syntax for renaming files with FileManagerLib

Does FileManagerLib have a dictionary? I tried to open it in SD and unlike some of your other libraries it just opened the library, it did not first ask me if I wanted to open the dictionary or the script.

Offline

 

#6 2019-06-14 12:19:31 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3577

Re: Finding the right syntax for renaming files with FileManagerLib

Yes it has.
You may reach it thru : File > Open Dictionary > Applications then navigate to the Script Libraries folder storing it.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 14 juin 2019  20:19:25

Offline

 

#7 2019-06-14 05:13:22 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5896

Re: Finding the right syntax for renaming files with FileManagerLib

chrisndeca wrote:

I tried to open it in SD and unlike some of your other libraries it just opened the library, it did not first ask me if I wanted to open the dictionary or the script.



That's odd -- I can't reproduce that. If it happens again, please drop me an email.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#8 2019-06-14 11:04:17 pm

chrisndeca
Member
From:: Oakland, CA
Registered: 2005-06-28
Posts: 19

Re: Finding the right syntax for renaming files with FileManagerLib

I was able to open the Dictionary using Yvan's advice.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)