image
image

Go Back   macosx.com > Scripts > Apple Scripts

Reply
 
LinkBack Thread Tools
  #17  
Old March 22nd, 2009, 01:06 PM
Registered User
 
Join Date: Feb 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
ejang is on a distinguished road
Thanks for the replication code!

Yesterday I tried to alter an example script that replaces the text in names on my desktop. I want to be able to set it so that the script automatically sets the search parameter as both file names and folders instead of a button prompt, but I am not sure how to notate this. Basically, I am trying to strip the script of its excess error messages and user choice.

Here is the code that I am trying to modify...

try
tell application "Finder" to set the source_folder to path to desktop folder as alias
end try
display dialog "Search and replace in:" buttons {"File Names", "Folder Names", "Both"} default button 3
set the search_parameter to the button returned of the result
Reply With Quote
  #18  
Old March 24th, 2009, 03:05 AM
Registered User
 
Join Date: Feb 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
ejang is on a distinguished road
I was sort of able to figure it out in that I could do

set the search_parameter to the "File Names"
or

set the search_parameter to the "Folder Names"

but I can't figure out how to do both.

Also How do I get a script to click a link on a webpage? I want to make a script application that clicks a login button on the safari web browser, can somebody show me an example of how this is done?

thanks!
Reply With Quote
  #19  
Old March 24th, 2009, 03:21 PM
Mikuro's Avatar
Crotchety UI Nitpicker
 
Join Date: Mar 2005
Posts: 2,679
Thanks: 6
Thanked 50 Times in 46 Posts
Mikuro will become famous soon enough
It looks like the script goes on to test search_parameter. My guess is you should say set the search_parameter to "Both". But there's probably a simpler way to do this by editing the later part of the script so that it just does what you want and doesn't bother testing search_parameter (assuming you're not using the option to search only folder or only file names).

As for the Safari question, this is more complicated. The only way I know of doing it is to tell Safari to execute a bit of JavaScript. So the first thing to do is to figure out how to push that button with JavaScript, and then send that JavaScript snippet to Safari via AppleScript. I have a simple example of this somewhere, let me see if I can find it....

Here we go:
Code:
tell application "Safari"
	do JavaScript "
	function x() {
	return document.title
	}
	x();
	" in tab 1 of window 1
end tell
That will pull the title of the active web page into your script.

I think there's a submit() method of either buttons or forms (or both) that will do what you need, but the trickier part is finding the right form button through the script. I'm not an expert with JavaScript, so I can only point you in the right direction. It's not a simple topic. If you're really interested, check out http://www.w3schools.com/js/js_obj_htmldom.asp
__________________
Mac mini — 1.25GHz G4, 1GB RAM — OS 10.5.8

Useful programs: Privoxy, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc
Reply With Quote
  #20  
Old March 24th, 2009, 07:56 PM
Registered User
 
Join Date: Feb 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
ejang is on a distinguished road
Hi,

thanks very much!
yeah I figured the "both" deal today by a little experimenting.

Thanks for the javascript link!
Reply With Quote
  #21  
Old March 24th, 2009, 08:16 PM
Registered User
 
Join Date: Feb 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
ejang is on a distinguished road
Hi once again,

I don't think this is possible, but I just wanted to check to see if this works at all...

I have an application that sends itself to the trash. Is there any way I can simultaneously quit that application and empty the trash at the same time? I can see how this can be done if I used a double-script file: one that opens the both of them, one that executes its process, then deleting itself. Then I can see how a timed delay can be integrated into the first script so that it empties the trash right after the second script finishes. Does anybody know how I can do this?

Pertaining to this question, I have thought of an abstract solution, but it is extremely inefficient and I am sure there is a faster way. One way to integrate these "double" scripts is to store one on the internet, have one script download the other and then open it automatically. This should be pretty easy except I don't know how to open the resulting downloaded file, on top of selecting "open" when the internet-application confirmation prompt appears on screen.

Thanks!
Reply With Quote
  #22  
Old June 29th, 2009, 11:23 AM
Registered User
 
Join Date: Jun 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
somotorcycle is on a distinguished road
Hi Mikuro,

Thanks for all your help on this forum. You're certainly adding a valuable service.

So I need to rename a file twice a day with one constant field and the current time stamp, e.g. s3759_20090629_0713. s3759 needs to stay constant and the date and time stamps follow in the above form.

Will you please advise me how to change your script to provide stamps in this format? After renaming the file, I'll need to have it automatically upload via ftp to a server.

Thanks for your help!


Andrew
Reply With Quote
Reply

Bookmarks

Tags
applescript, duplicate, finder, script, timestamp

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump


All times are GMT -5. The time now is 06:07 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC1
Copyright 2000-2010 DigitalCrowd, Inc.