![]() |
hi,
I am writing the following script: tell application "BBEdit" set new_file to "/Users/admin/Desktop/test.conf" open new_file ??//replace "line x" by "line y"//?? end tell As you can see, I want to be able to "find and replace" a specific text with another....how can i do this? thx |
The crux of this is how to identify the line that is to be changed. You need to be able to tell BBBedit how to identify this line - e.g. by some text string that is contained in that line, by the line number, etc.
|
You can do this without a text editor (unless you need the editor for other things) by using AppleScript's text item delimiters.
Code:
set new_file to alias "Users:admin:Desktop:test.conf" |
thx for the reply guys...however Carl i tried ur script but it seems that i am receiving a syntax error saying: File Users:admin:Desktop:test.conf wasn't found.
|
I just used the path in your first post as an example. Replace what's there with the location of the actual original .conf file.
|
But it is a correct location...the file is in the Desktop...and i am still receiving this error...
|
One more thing....when i am removing the "alias" i am receiving an Apple "Script Error saying that: Can't make "Users:admin:Desktop:testing" into a file"
|
Don't remove the alias.
Try using set new_file to alias (((path to desktop) & "test.conf") as Unicode text) EDIT: I forgot to mention in my original suggested script that you need to reset your delimiters back to the default: set AppleScript's text item delimiters to "" |
Quote:
replace "Macintosh HD" with your hard disk name "Macintosh HD:Users:admin:Desktop:test.conf" |
It worked guys!!!
one last thing....do u know how i could save this in the original file..?? :D!!thx |
I am trying to do the following but it is not working....
Check the last line plz (save....): set new_file to alias (("RDServer HD:Users:admin:Desktop:testing.txt") as Unicode text) set AppleScript's text item delimiters to "" set AppleScript's text item delimiters to "good" set text_items_of_new_file to text items of (read new_file) --A list that contains 2 chunks of text: Everything before the original line, and everything after set AppleScript's text item delimiters to "nice" set NEW_new_file to text_items_of_new_file as Unicode text --New text for your new conf file save NEW_new_file in alias (("RDServer HD:Users:admin:Desktop:testing.txt") as Unicode text) |
Refreshing Applescript Text Delimiters
I come up to do this script for now.....and its working fine....but the problem:confused: is that i can only do it once and i cannot edit the text anymore....how can i refresh the applescript delimiters...and start again..!!
Heres the script: set new_file to alias (("RDServer HD:Users:admin:Desktop:Tita copy.txt") as Unicode text) set AppleScript's text item delimiters to "" set AppleScript's text item delimiters to "Mono" set text_items_of_new_file to text items of (read new_file) --A list that contains 2 chunks of text: Everything before the original line, and everything after set AppleScript's text item delimiters to "tatou" set NEW_new_file to text_items_of_new_file as Unicode text --New text for your new conf file display dialog the NEW_new_file write NEW_new_file to alias (("RDServer HD:Users:admin:desktop:Tita copy.txt") as Unicode text) thx!!! :) |
Sorry, I meant to reply but forgot :(
You can use a dialog to ask the user to enter the text each time the script is ran. Also, the line 'set AppleScript's text item delimiters to ""' should be the last line of the script. |
When posting code containing the character pair :D
it would probably be a good thing to check the box labeled "Disable smilies in text" from the Additional Options below the Reply to Thread editing section. :D |
The refresh did not work..:(..One last thing guys instead of putting /Users/admin/public..."admin" beeing the shortname of the current users...i want to be able to find the shortname in the script and replace it automatically...i dont want to do it manually...this is the aim of the whole script...so if you can help in that plz!!!
:D |
guys i want to thank you for the help...but i need a last favor....
How can i get the name of my Hard Disk...using applescript!!! Please its an urgent matter...!! thx! :) |
tell application "Finder" to set HD to name of startup disk
|
Or…
set HD to text 1 thru -2 of (path to startup disk as Unicode text) |
Quote:
|
Thx man!! it worked but it seems i have some problems with permissions on folder. do u know how can we change a folder permissions??
all i know about this subject is this script: tell application "Finder" make new folder at desktop with properties {name:"aNewFolder", owner privileges:{read write}} end tell |
need help urgently
hi guys...i really need an answer on the last post reply i worte....it is a matter of life and death with my boss!!!!:eek: !!!!!
|
need help urgently
hi guys...i really need an answer on the last post reply i worte....it is a matter of life and death with my boss!!!!:eek: !!!!!
this was it: Thx man!! it worked but it seems i have some problems with permissions on folder. do u know how can we change a folder permissions?? all i know about this subject is this script: tell application "Finder" make new folder at desktop with properties {name:"aNewFolder", owner privileges:{read write}} end tell |
do shell script "mkdir -p -m 700 ~/Desktop/newdir"
Uh, you never said what permissions you wanted. 700 is secure. 777 is insecure. Tweak as desired. -HI- |
i want read write permission on an already created folder...not a new one,,,!!!
tk. |
read write ... but no "execute"!?!?!?
read write for who besides owner (group and/everyone)??? You are not at all clear. What's wrong with the permissions? When a user creates a folder on their desktop, they already get read write and execute (search) permissions. Study some UNIX (like man chmod). Anyway, this should do: do shell script "chmod 777 ~/Desktop/foldername" |
i really need some urgent help overhere guys....
i need to change the permission of an already present file.... someone mentioned a do shell script.... tk. |
thx guys....
i dont know but it seems i had some rfreshing problem....i couldnt see the new things u wrote.... anyways thx again....it WORKED....m SAVED!! :D!! |
Hi,
I am writing the following script which consist of editing a file automatically using applescript...my problem is that i can only perform the modification ONCE!! set hd to path to desktop set astid to AppleScript's text item delimiters set AppleScript's text item delimiters to ":" set hdname to first text item of (hd as string) set AppleScript's text item delimiters to astid set httpd_old to alias ((hdname & ":Testfolder:test.txt") as Unicode text) set AppleScript's text item delimiters to "" set AppleScript's text item delimiters to "a path to edit" set text_items_of_httpd_old to text items of (read httpd_old) --A list that contains 2 chunks of text: Everything before the original line, and everything after set publFolder to (path to "pubb") set uPath to POSIX path of publFolder set u2Path to uPath & theName set AppleScript's text item delimiters to u2Path set httpd_new to text_items_of_httpd_old as Unicode text --New text for your new conf file write httpd_new to alias ((hdname & ":Testfolder:test.txt") as Unicode text) When i run the script for the first time....the path changes.....but if i need to do it and edit something else....it keep giving me the same result.... can u help me with it please....if there is anything unclear about the script let me know...!! tk. |
need helpp!!!
anyone availble guys
|
need helpp!!!
anyone available guys
|
| All times are GMT -5. The time now is 06:04 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.