Jump to content
  • 0

Naam van bestand wijzigen m.b.v. Applescript


hezndepezn

Question

Posted

Ik wil vanuit een FM de naam van een bestand te wijzigen (dit i.v.m. een updateroutine). Nu heb ik een stukje Applescript gemaakt ( zover mijn kennis reikt 8O ) om dit voor elkaar te krijgen maar loop telkens tegen dezelfde fout aan.

De folder waar het bestand in staat kan variëren, ik krijg het wel voor elkaar om dat pad uit te lezen, maar het wijzigen van de naam van het bestand dat zich daar bevindt gaat fout. Ik krijg deze melding:

error "\"test\" kan niet in type integer worden omgezet." number -1700 from "test" to integer

 

Dit is het script dat ik gebruik. Er zit (tijdelijk) een dialoog in om het pad te kunnen controleren. Dit test ik eerst in scripteditor waarna (als het werkt) ik het in FM ga gebruiken. ( in een ander bestand dan waarvan de naam moet worden gewijzigd 8) )

 

tell application "Finder"

set thePath to POSIX path of ((path to me as string) & "::")

display dialog thePath buttons {"Clipboard", "OK"} default button 2

if the button returned of the result is "Clipboard" then

set the clipboard to thePath

end if

set name of document file "test" of thePath to "test_OLD"

end tell

 

Wie helpt mij uit de brand.

2 answers to this question

Recommended Posts

  • 0
Posted

Ik ben er inmiddels uit, ipv finder het werk laten doen "tell "System Events" gebruiken, had dit al eens geprobeerd maar daar zaten cruciale grammatica fouten in :wink: .

 

tell application "Finder"

set thePath to POSIX path of ((path to me as text) & "::")

set sourceFolder to thePath

display dialog thePath buttons {"Clipboard", "OK"} default button 2

if the button returned of the result is "Clipboard" then

set the clipboard to thePath

end if

tell application "System Events" to set name of file (thePath & "test") to "test_OLD"

end tell

  • 0
Posted

Script in FM geïmplementeerd blijkt dat het pad niet aan het geopende bestand wordt gerelateerd maar aan FM-zelf :( . Heb het pad uit FM gehaald (berekend script).

Ziet er in FM nu zo uit.

 

"tell application \"Finder\"¶

set thePath to" & "\"" & Updater::huidig pad minus bestand & "\"" & "¶

display dialog thePath buttons {\"Clipboard\", \"OK\"} default button 2¶

if the button returned of the result is \"Clipboard\" then¶

set the clipboard to thePath¶

end if¶

tell application \"System Events\" to set name of file (thePath & \"test\") to \"test_OLD\"¶

end tell¶"

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...