Simple Apple Script Required
Hey
Im looking for a simple AppleScript i can run on client workstations , The Script ideally needs to do the following ..
- Find any files in the User's Home folder with a Creation date older than 3 years ago.
- Display the files and allow user to delete.
Im sure this is quite simple for someone who knows what there doing with AppleScript ! , anyone have any simple scripts they could suggest ?
Cheers
Well, getting a list of files is one thing (there are several shell utilities), getting them in a Finder window so you can do various things with them is another. There isn't much AppleScript support for the Finder's Find…, and saved searches don't appear to be portable. GUI scripting is more akin to voodoo, but I figured I would give it a shot to see if I could get close.
The following script pastes the appropriate search term in the Search item in a Finder window's toolbar. Getting the search to start in a specific place is a bit goofy, but if you have navigated to the desired folder, running the script should start the search from there:
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px; height: 340px;
color: #000000;
background-color: #FFDDFF;
overflow: auto;"
title="this text can be pasted into the Script Editor">
-- enter a search term in the Finder's search toolbar item
-- set the search date
tell ((current date) as «class isot» as string)
(get text 1 thru 4) - 3 -- the current year - 3
set SearchDate to text 6 thru 7 & "/" & text 9 thru 10 & "/" & result
end tell
-- make sure there is a Finder window and the toolbar is showing
tell application "Finder"
activate
if (get windows) is {} then set target of (make new Finder window) to path to home folder
if not toolbar visible of front window then set toolbar visible of front window to true
end tell
-- enter the search term into the search text field, if present
tell application "System Events"
if UI elements enabled then
get value of attribute "AXRoleDescription" of text field 1 of group 1 of tool bar of front window of application process "Finder"
if (result as text) is "search text field" then -- toolbar search item exists
set value of text field 1 of group 1 of tool bar of front window of application process "Finder" to "created:<=" & SearchDate
else -- oops
activate
display dialog "This script needs to use the Search item on the toolbar - please customize the Finder toolbar to include Search." with title "Find by creation date" buttons {"OK"} default button 1
end if
else
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.universalaccess"
display dialog "This script needs UI element scripting enabled. Check \"Enable access for assistive devices\" and try again." with title "Find by creation date" buttons {"OK"} default button 1
end tell
end if
end tell
</pre>
HTH
Similar Messages
-
Trying to write a simple apple script to reveal a file.
This is what I have now:
tell application "Finder" to reveal POSIX path of "/Users/lloyd/Desktop/my file.txt"
but I get this error:
error "Finder got an error: Can’t make \"/Users/lloyd/Desktop/my file.txt\" into type item." number -1700 from "/Users/lloyd/Desktop/my file.txt" to item
Any help is much appreciatedThanks for the quick answer. Tried changing to file but am now getting this error:
error "Can’t get POSIX file of \"/Users/lloyd/Desktop/my file.txt\"." number -1728 from POSIX file of "/Users/lloyd/Desktop/my file.txt"
btw, I meant to type reveal instead of open but don't think that should be a problem right? The file exists on the desktop, does the space in the file name create a problem? -
APPLE SCRIPT HELP! Simple Renaming Script
I dont have any experience with apple script but desperately needed this for a work issue. I basically have tons of files with all the same type of name and need to send the first two numbers in the file to the end of the file as a suffix... so this...
01 alexa_02.mp3
needs to turn into this
01 alexa_02_01.mp3
So the function is take the first two characters from the file name of all the files in the folder and rename them with a suffix. Here is what I have so far.
PLEASE HELP! Im desperate!
[CODE]try
tell application "Finder" to set the source_folder to (choose folder with prompt "Pick the folder containing the files to rename:") as alias
end try
display dialog "Change Suffix to First Two Characters of File Name:" buttons {"Send The Pids!", "Cancel"}
set the button_pressed to the button returned of the result
set the item_list to list folder source_folder without invisibles
set source_folder to source_folder as string
repeat with i from 1 to number of items in the item_list
set this_item to item i of the item_list
set this_item to (source_folder & this_item) as alias
set this_info to info for this_item
set the current_name to the name of this_info
tell application "Finder"
if the button_pressed is "Send The Pids!" then
set the filename to the (current_name & the characters 1 thru 2 of current_name) as string
set orig to quoted form of POSIX path of current_name
set dest to source_folder & filename
try
set y to dest as alias
on error
set dest to quoted form of POSIX path of dest
set command to "mv " & orig & " " & dest
do shell script command
end try
end if
end tell
end repeat[/CODE]Made a short script on my own... normally you could do this using the Finder and run a recursive algorythm, but if you just use find to find all files in a folder that ft your criteria and use these links to generate a list of aliases (posix files) it is way faster and acomplished with less code :-)
set myfolder to characters 1 through -2 of (POSIX path of ((choose folder) as alias)) as text
set foundfiles to every paragraph of (do shell script "find " & quoted form of myfolder & " -type f -iname \"*.mp3\"")
repeat with afile in foundfiles
set afile to ((afile as text) as POSIX file as alias)
tell application "Finder"
set filename to name of afile
set filesuffix to (characters -4 through -1 of filename) as text
set addonsuffix to characters 1 through 2 of filename
set filename to (characters 1 through -5 of filename) as text
set newfilename to filename & "_" & addonsuffix & filesuffix
set name of afile to newfilename
end tell
end repeat -
Apple Script - Simple Navigation thru Preferences
Howdy,
I'm trying to us Apple Script to simply change my Network Location. I thought it would be easy, I must be missing something. Here is the code I've written so far that works...
tell application "System Preferences"
activate
set current pane to pane "Network"
end tell
Now, I want to change the Location field (I believe it's called an anchor) to my secondary (Home, for example). So, I added a line like such...
tell application "System Preferences"
activate
set current pane to pane "Network"
set anchor to "Location"
end tell
This 4th line doesn't work, but you get the idea. I have written many variations of this 4th line (i.e. 'set "Location" to "Home"'), nothing seems to work. And there doesn't seem to be much documentation on anchors (other than what's in the Dictionary).
Recording doesn't save it, so that's out of the question.
Does anyone have any ideas?? Thanks.
Bryan
iMac Intel Mac OS X (10.4.7)
iMac Intel Mac OS X (10.4.7)Surround the line...
click button "Apply" of sheet 1
... with 'try ... end try', as shown below ...
try
click button "Apply" of sheet 1 -- Select the'Apply' button of drop down sheet.
end try
Full code, with comments:
property tMenu : "Home" -- The menu item to select.
tell application "System Preferences" -- Launch application
activate
set current pane to pane "com.apple.preference.network" -- Select 'Network' utility.
end tell
tell application "System Events" to tell process "System Preferences"
tell window 1
click pop up button 1 -- Select the 'Localtion' popup button.
click menu item tMenu of menu 1 of pop up button 1 -- Select the 'tMenu' menu item.
click button "Apply Now" -- Select the 'Apply Now' button.
click button 1 -- Select the Close button.
try
click button "Apply" of sheet 1 -- Select the'Apply' button of drop down sheet.
end try
end tell
end tell -
Apple Script vs. Java Script
I'm looking to learn a small amount of programing for a project that I am working on. I know some Lingo from using Director MX. Tonight I bought a book for Unix but found that is mostly line-commands and I don't think Apple Script is exactly what I need.
I have many computers at remote locations that I need to dial into and I use a telnet protocal to control the unit and another FTP program to upload files. I would like to create 1 window app that I can do both with. Using the command line in the terminal window I can FTP items and also use the telnet to control the units. But as far as I can tell I can't build an interface with unix.
Is Jave the best way to go here? I know C++ would require a huge learning curve. But if Java is clost to Lingo then it would eas the learning curve.
Thanks,
-LarsHey Reese thanks for the reply. Actualy i'm not connecting to Macs on the other end other wise that would be a perfect solution. I'm connecting to little shoe size computers by Adtec. The ony way to upload things to these units are with an FTP program and then I use a telnet program to send commands like PLAY, STOP, LIST and so on.
A person came out with a app just for this called Fathom which I use on the mac, but it's the only one. Since I can FTP and use the telnet within the Terminal I thought it would be fun to build a scaled down version of that app. Plus I pay money for that app everytime I add a new hotel that I need to talk to.
So would Java be a good program to build a simple window and use functions from UNIX with in JAVA?
-Lars -
How can I get the size of a file with apple script
I try to get the size of a file within an apple script. But I did not find information how to do this.
There are two ways. I think Apple is moving toward using System Events, which is listed first.tell application "Finder"
set myFile to selection as alias
--this just gets a file for me to work with
--coercing it into an alias is required for the other functions
end tell
tell application "System Events"
get size of myFile
end tell
set myInfo to (info for myFile)
get size of myInfo -
Install and uninstall of dmg file using Apple script in Mac 10.6 and higher version.
Hi ,
Could anyone please help me to write a Apple script to Install dmg file and do clean uninstall in Mac 10.6.8 and higher version.
My requirement is:
When i run script : it has to install the dmg file which is located inside one desktop folder say 'New Folder'
I need to do clean unistall when i run the script: i need to delete the folder in ~/Library- locate folder say 'CPSPCSHOWSERVER'' move to trash and from Terminal type in command "rm -r ~/.CPS' to completely delte this folder.
Really appreciated all ur help!!
Thanks,
KT.http://macfidelity.de/2008/08/30/how-to-mount-a-dmg-from-terminal-in-mac-os-x/in dex.html
http://osxdaily.com/2011/12/17/mount-a-dmg-from-the-command-line-in-mac-os-x/
http://hints.macworld.com/article.php?story=20030614230204397
http://www.commandlinefu.com/commands/view/2031/install-an-mpkg-from-the-command -line-on-osx -
XML Comment in Indesign using Apple script.
Hi all,
How to find the selected XML element is commented in indesign and get XML comment value in thru apple script. Any Ideas?
-JacinthaYou can have as many comments as you want so they require you to state the index of the comment in your reference.
Assuming you have an object reference for the XML element, you would replace "associated XML element of selection" with that.
tell application "Adobe InDesign CS3"
set myComments to {}
if every XML comment of associated XML element of selection is not {} then
set end of myComments to value of every XML comment of associated XML element of selection
end if
return myComments
end tell
if you know there's only going to be one comment then,
tell application "Adobe InDesign CS3"
if every XML comment of associated XML element of selection is not {} then
set myComment to value of XML comment 1 of associated XML element of selection
end if
return myComment
end tell
~Mike -
Apple script for 10.4 - works in OSX but not older
Hi I have a script which I'm using on my current system 10.9 it runs in excel and it goes something like this:
tell application "Microsoft Excel"
-- put the complete set of data into a list of lists (i.e., 2 dimensions -> columns of rows)
tell active sheet to set myData to value of used range
-- recipient email
set myRow1 to 1
set myCol1 to 1
set Address to item {myCol1} of item {myRow1} of myData
-- recipient name
set myCol4 to 4
set rName to item {myCol4} of item {myRow1} of myData
The above is just a small snippet from the script. However I try running this on apple 10.4 apple script and it does not work. I'm trying to save my computer time from have to this minimal task on an older mac I have but I'm experiencing some problems. Does the active sheet not work in apple mac 10.4? What am I missing? Any help would be greatly appreciated.Hi Ohms238,
I found this Apple developer page that talks about changes made in each version of OSX. It will require some work, but you can go through and see what changes are relevant to your script.
But I would actually recommend running pieces of your code separately to see exactly what parts don't work and then rewrite just those portions. -
Apple Script to Sort through the Address Book
Dear All,
I am quite new to Apple and just a learner on Apple-scripts. Its been quite a task to learn.. I would require some help on a few things..
The script will eventually use numbers to send email and get the user inputs and any yet to reach there..
After going through lots of scripts to sort through the address book and make a clean address book, i found they are quite slow in processing takes about 20~30 Minutes to get through 2000 Contacts..
Hence after reading posting of Mr. Koenig & Mr. Hiroto and specifically on deep copy. I have written the following code which does the following on 2000 records within 6~8Mins.
The Script work its way through all the contact is the address List.. and creates Groups
1. Duplicate Email Id's — List of Contacts with same email ID's including Contacts where the email Id is entered twice.. (Strange.. Address Book Issue, copy of the email Id under work & home)
2. Duplicate Phone — List of Contacts with same Phone Numbers including Contacts where the Phone Nos is entered twice.
3. Duplicate Name — List of Contacts with Same Names
4. Duplicate No Name — List of Contacts without the First Name and Last Name
it also sort the Contacts under the following Group which you can edit later with all the information's..
1. Only Email Ids — List of Contacts with Email ID and No Phone Numbers
2. Only Phone — List of Contacts with Phone Numbers and No Email Id's
3. No Email or Phone — List of Contacts with No Email Id's and No Phone numbers (some half completed contacts )
My Question to the forum is why is the following code still taking too much time..
set onlyDupEList to every person of group theGroupEmail
repeat with j from 1 to count of Dup_email
set tempdata to item j of Dup_email
if onlyDupEList does not contain {tempdata} then add tempdata to group theGroupEmail
end repeat
save application "Address Book"
and the scripts slows down when the items in the list is quite large (over 800 or so )..
Any help is appreciated and thanks in advance..
-- the code ---
global MsgTitle
on run
set MsgTitle to "Search for Duplicates in Address Book Contacts"
display dialog ¬
"This Script takes a while to finish" & return & "maybe 10 min or More..." & return & "Depending on the Address Book Contacts." & return & return & "Hence Allow it to run for the while" with title MsgTitle ¬
with icon 1 ¬
buttons {"Continue"} ¬
giving up after 5
set question to display dialog "Select the Duplicate Search Parameter " with icon 1 with title MsgTitle ¬
buttons {"Contact Name", "Contacts on Phone & Email Id's", "Quit"} default button 3
set rtnValue to button returned of question
if rtnValue is "Quit" then
-- tell application "Address Book" to quit
tell me to quit
end if
if rtnValue is "Contact Name" then
-- tell application "Address Book" to quit
GetDup_byName("Duplicate Name")
end if
if rtnValue is "Contacts on Phone & Email Id's" then --Contacts on Phone & Email Id's
-- tell application "Address Book" to quit
Get_dup()
end if
end run
--- Search on Name Field ---
on GetDup_byName(theGroupName)
set question to display dialog "Do you want to search for duplicates based on Names? " with icon 0 with title MsgTitle ¬
buttons {"Continue", "Quit"} default button 1
set rtnValue to button returned of question
if rtnValue is "Quit" then
-- tell application "Address Book" to quit
tell me to quit
end if
tell application "Address Book"
activate
set biglist to {}
set NoNameList to {}
set theGroupNoName to "Duplicates No Names"
set theGroup to theGroupName
-- if not (exists (group "Dupilicate Entries")) then
if not (exists (group theGroup)) then
make new group with properties {name:theGroup}
save
end if
if not (exists (group theGroupNoName)) then
make new group with properties {name:theGroupNoName}
save
end if
set the_names to name of people
repeat with i from 1 to number of items in the_names
set theName to item i of the_names
-- return theName
if theName is not in biglist then
copy theName to end of biglist
else
set counter to (people whose name is theName)
if (count of counter) > 1 then
repeat with i from 1 to number of items in counter
set this_item to item i of counter
-- display dialog this_item
add this_item to group theGroup
end repeat
-- return counter as string
end if
end if
-- captures the Contacts without Name ---
if theName contains "@" then
-- display dialog theName
set counterList to (people whose name is theName)
repeat with i from 1 to number of items in counterList
set this_item to item i of counterList
-- display dialog this_item
add this_item to group theGroupNoName
end repeat
end if
-- save application "Address Book"
end repeat
save application "Address Book"
set peopleCount to (count every person)
-- set peopleCount to 50 -- only for testing --
repeat with i from 1 to peopleCount
set first_name to first name of person i as string
set Last_Name to last name of person i as string
if first_name is equal to "missing value" and Last_Name is equal to "missing value" then
-- display dialog first_name & " : " & Last_Name
set end of NoNameList to (id of person i)
end if
end repeat
repeat with j from 1 to the count of NoNameList
set tempdata to item j of NoNameList
-- set testdata to person id tempdata
-- if (name of groups of testdata does not contain theGroupNoEmail) then
add tempdata to group theGroupNoName
-- end if
end repeat
save application "Address Book"*)
display dialog ¬
"This Script Finished Processing Address Book Contacts the Duplicates are in the group" with title MsgTitle ¬
with icon 1 ¬
buttons {"Continue"} ¬
giving up after 5
end tell
end GetDup_byName
on Get_dup()
set question to display dialog "Do you want to search for duplicates based on Names? " with icon 0 with title MsgTitle ¬
buttons {"Continue", "Quit"} default button 1
set rtnValue to button returned of question
if rtnValue is "Quit" then
-- tell application "Address Book" to quit
tell me to quit
end if
tell application "Address Book"
activate
set theGroupEmail to "Duplicate Email Id's"
set theGroupPhone to "Duplicate Phone"
set theGroupNoEmail to "Only Phone Numbers"
set thegroupNoPhone to "Only Email Id's"
set theGroupNoData to "No Email or Phone"
-- set theGroup to theGroupName
if not (exists (group theGroupEmail)) then
make new group with properties {name:theGroupEmail}
save "Address Book"
end if
if not (exists (group theGroupPhone)) then
make new group with properties {name:theGroupPhone}
save "Address Book"
end if
if not (exists (group theGroupNoEmail)) then
make new group with properties {name:theGroupNoEmail}
save "Address Book"
end if
if not (exists (group thegroupNoPhone)) then
make new group with properties {name:thegroupNoPhone}
save "Address Book"
end if
if not (exists (group theGroupNoData)) then
make new group with properties {name:theGroupNoData}
save "Address Book"
end if
set ListofPeople to people --the_ID
set ListofEmailID to value of emails of people --the_emails
-- return ListofEmailID
set ListofPhones to value of phone of people -- the_phones
-- return ListofPhones
set biglist to {}
set ListEmail_Uniq to {}
set ListEmail_Dup to {}
set No_PhoneList to {}
set No_EmailList to {}
set No_dataList to {}
set FlagEmail to false
set FlagPhone to false
-- repeat with i from 1 to number of items in the_emails
repeat with i from 1 to count of ListofEmailID
set thePersonID to item i of ListofPeople
set theEmails to item i of ListofEmailID
if theEmails is equal to {} then
set end of No_EmailList to thePersonID
else
-- set FlagEmail to true
repeat with j from 1 to count of theEmails
set tmpdata to item j of theEmails
-- return tmpdata
if tmpdata is not in biglist then
set end of biglist to tmpdata
set end of ListEmail_Uniq to {tmpdata} & {thePersonID}
else
set end of ListEmail_Dup to {tmpdata} & {thePersonID}
end if
end repeat
end if
end repeat
-- return ListEmail_Uniq
-- return ListEmail_Dup
-- save application "Address Book"
set biglist to {}
set ListPhone_Uniq to {}
set ListPhone_Dup to {}
-- repeat with i from 1 to number of items in the_emails
repeat with i from 1 to count of ListofPhones
set thePersonID to item i of ListofPeople
set thePhones to item i of ListofPhones
if thePhones is equal to {} then
set end of No_PhoneList to thePersonID
else
-- set FlagPhone to true
repeat with j from 1 to count of thePhones
set tmpdata to item j of thePhones
-- return tmpdata
if tmpdata is not in biglist then
set end of biglist to tmpdata
set end of ListPhone_Uniq to {tmpdata} & {thePersonID}
else
set end of ListPhone_Dup to {tmpdata} & {thePersonID}
end if
end repeat
end if
end repeat
-- return ListPhone_Uniq
-- return ListPhone_Dup
set the Dup_email to {}
-- Find the Duplicates from the sorted list --
repeat with i from 1 to the count of ListEmail_Dup
set tempdata to item i of ListEmail_Dup
set dataEmailDup to item 1 of tempdata
set dataPersonDup to item 2 of tempdata
repeat with j from 1 to the count of ListEmail_Uniq
set tempdata to item j of ListEmail_Uniq
set dataEmailUniq to item 1 of tempdata
set dataPersonUniq to item 2 of tempdata
-- display dialog mainEmail1 & "=" & mainEmail2 & " " & mainID1 & "=" & mainID2
if dataEmailDup is equal to dataEmailUniq then
set end of Dup_email to dataPersonDup -- & "," & dataPersonUniq
set end of Dup_email to dataPersonUniq
end if
(* -- the code takes lot more time if add to group was used --
if dataEmailDup is equal to dataEmailUniq then
set testdata to person id dataPersonDup
add testdata to group theGroup
set testdata to person id dataPersonUniq
add testdata to group theGroup
end if
end repeat
end repeat
-- return Dup_email
set the Dup_Phone to {}
-- Find the Duplicates from the sorted list --
repeat with i from 1 to the count of ListPhone_Dup
set tempdata to item i of ListPhone_Dup
set dataPhoneDup to item 1 of tempdata
set dataPersonDup to item 2 of tempdata
repeat with j from 1 to the count of ListPhone_Uniq
set tempdata to item j of ListPhone_Uniq
set dataPhoneUniq to item 1 of tempdata
set dataPersonUniq to item 2 of tempdata
-- display dialog mainEmail1 & "=" & mainEmail2 & " " & mainID1 & "=" & mainID2
if dataPhoneDup is equal to dataPhoneUniq then
set end of Dup_Phone to dataPersonDup -- & "," & dataPersonUniq
set end of Dup_Phone to dataPersonUniq
end if
(*if dataPhoneDup is equal to dataPhoneUniq then
set testdata to person id dataPersonDup
add testdata to group theGroup
set testdata to person id dataPersonUniq
add testdata to group theGroup
-- save
end if*)
end repeat
end repeat
-- return Dup_Phone
set onlyDupEList to every person of group theGroupEmail
repeat with j from 1 to count of Dup_email
set tempdata to item j of Dup_email
if onlyDupEList does not contain {tempdata} then add tempdata to group theGroupEmail
end repeat
save application "Address Book"
set onlyDupPList to every person of group theGroupPhone
repeat with j from 1 to count of Dup_Phone
set tempdata to item j of Dup_Phone
if onlyDupPList does not contain {tempdata} then add tempdata to group theGroupPhone
end repeat
save application "Address Book"
set onlyPhoneList to every person of group theGroupNoEmail
repeat with j from 1 to the count of No_EmailList
set tempdata1 to item j of No_EmailList
if No_PhoneList does not contain {tempdata1} then
if onlyPhoneList does not contain {tempdata1} then add tempdata1 to group theGroupNoEmail
end if
(*set flagE to false
repeat with i from 1 to the count of No_PhoneList
set tempdata2 to item i of No_PhoneList
if tempdata1 is equal to tempdata2 then
set flagE to true
exit repeat
end if
end repeat
if flagE is false then add tempdata1 to group theGroupNoEmail*)
end repeat
save application "Address Book"
set onlyEmailList to every person of group thegroupNoPhone
repeat with j from 1 to the count of No_PhoneList
set tempdata1 to item j of No_PhoneList
if No_EmailList does not contain {tempdata1} then
if onlyEmailList does not contain {tempdata1} then add tempdata1 to group thegroupNoPhone
end if
end repeat
save application "Address Book"
set onlyList to every person of group theGroupNoData
repeat with i from 1 to count of ListofPeople
if (item i of ListofEmailID is equal to {}) and (item i of ListofPhones is equal to {}) then
set tempdata to item i of ListofPeople
if onlyList does not contain {tempdata} then add tempdata to group theGroupNoData
end if
end repeat
save application "Address Book"
display dialog ¬
"This Script Finished Processing Address Book Contacts the Duplicates are in the group" with title MsgTitle ¬
with icon 1 ¬
buttons {"Continue"} ¬
giving up after 5
end tell
end Get_dup
on quit
--set MsgTitle to "Change Email ID's Domain Name"
save application "Address Book"
display dialog "Contact Srikanth Kamath at [email protected] for any Help" with title MsgTitle with icon 1 buttons "OK"
continue quit
end quitHello Srikanth Kamath,
I'm not sure you're still following this thread, but anyway here's sample code I said I'd post later.
--SCRIPT2
main()
on main()
script o
-- input data
property xx : {1, 2, 3, 4, 5} -- list of parents
property yy : {{"g", "h"}, {"a", "b"}, {"b", "e", "f"}, {"e"}, {"c", "d"}} -- list of children per parent
-- work list
property pp : {} -- list of children tagged by parent; i.e, lits of {child, parent}
property qq : {}
property rr : {}
-- (1) build list of children tagged by parent
repeat with i from 1 to count my xx
set x to my xx's item i
set y to my yy's item i
repeat with p in y
set end of my pp to {p's contents, x}
end repeat
end repeat
--return pp -- {{"g", 1}, {"h", 1}, {"a", 2}, {"b", 2}, {"b", 3}, {"e", 3}, {"f", 3}, {"e", 4}, {"c", 5}, {"d", 5}}
-- (2) sort tagged list by child as key
msort(my by_key1, my pp)
--return pp -- {{"a", 2}, {"b", 2}, {"b", 3}, {"c", 5}, {"d", 5}, {"e", 3}, {"e", 4}, {"f", 3}, {"g", 1}, {"h", 1}}
-- (3) retrieve parents with duplicate child
(* retrieve list of {child, parent} for duplicate child *)
set my qq to uniq(my eq_key1, my pp, {_dup:true})
--return qq -- {{"b", 2}, {"b", 3}, {"e", 3}, {"e", 4}}
(* retrieve list of parent *)
repeat with q in my qq
set r to q's item 2
if r is not in my rr then set end of my rr to r
end repeat
return rr -- {2, 3, 4}
end script
tell o to run
end main
on by_key1(x, y)
msort's comparator for list of lists
key = item 1, ascending
returns true iff x and y are out of order
return x's item 1 > y's item 1
end by_key1
on eq_key1(x, y)
uniq's comparator for list of lists
key = item 1
returns true iff x and y are considered equal
return x's item 1 = y's item 1
end eq_key1
on msort(cmp_, aa) -- v1.2f2
Basic recursive merge sort handler having list sorted in place.
handler cmp_ : comparator
* cmp_(x, y) must return true iff list element x and y are out of order.
list aa : list to be sorted in place
script o
property parent : {} -- limit closure to minimum
property xx : aa -- to be sorted in place
property xxl : count my xx
property yy : {}
property cmp : cmp_
on merge(p, q, r)
property xx: source list
integer p, q, r : absolute indices to specify range to be merged such that
xx's items p thru r is the target range,
xx's items p thru (q-1) is the first sublist,
xx's items q thru r is the second sublist.
(p < q <= r)
local i, j, k, xp, xr, yi, yj, ix, jx
if r - p = 1 then
set xp to my xx's item p
set xr to my xx's item r
if my cmp(xp, xr) then
set my xx's item p to xr
set my xx's item r to xp
end if
return -- exit
else
if p < q - 1 then merge(p, (p + q) div 2, q - 1)
merge(q, (q + r + 1) div 2, r)
end if
At this point, sublits xx[p, q-1] and xx[q, r] have been already sorted (p < q <= r)
if my cmp(my xx's item (q - 1), my xx's item q) then
else -- xx[p, q-1] & xx[q, r] are already sorted
return
end if
set yy to my xx's items p thru r -- working copy for comparison
set ix to q - p
set jx to r - p + 1
set i to 1
set j to q - p + 1
set k to p
set yi to my yy's item i
set yj to my yy's item j
repeat
if my cmp(yi, yj) then
set my xx's item k to yj
set j to j + 1
set k to k + 1
if j > jx then
set my xx's item k to yi
set i to i + 1
set k to k + 1
repeat until k > r
set my xx's item k to my yy's item i
set i to i + 1
set k to k + 1
end repeat
return
end if
set yj to my yy's item j
else
set my xx's item k to yi
set i to i + 1
set k to k + 1
if i > ix then
set my xx's item k to yj
set j to j + 1
set k to k + 1
repeat until k > r
set my xx's item k to my yy's item j
set j to j + 1
set k to k + 1
end repeat
return
end if
set yi to my yy's item i
end if
end repeat
end merge
on cmp(x, y)
(* primary comparator *)
return x > y
end cmp
local d, i, j
if xxl ≤ 1 then return
if cmp_ = {} then set my cmp to cmp -- comparator fallback
my merge(1, (xxl + 1) div 2, xxl)
end script
tell o to run
end msort
on uniq(eq_, aa, {dup:dup}) -- v0.21
handler eq_ : comparator eq_(x, y) that returns true iff x and y are considered equal
list aa : pre-sorted list
(precisely, a list organized such that any duplicate items are adjacent to each other)
boolean _dup : option whether return unique items or duplicate items
return duplicate if true, unique otherwise.
script o
property parent : {} -- limit closure to minimum
property xx : aa
property yy : {}
property eq : eq_
on eq(x, y)
(* primitive comparator *)
x = y
end eq
if eq_ = {} then set my eq to my eq -- comparator fallback
local t, x, _on
if (count my xx) < 2 then return my xx's contents
if _dup then
set _on to false
set t to my xx's item 1
repeat with i from 2 to count my xx
set x to my xx's item i
if eq(x, t) then
set end of my yy to t
set _on to true
else if _on then
set end of my yy to t
set _on to false
end if
set t to x
end repeat
if _on then set end of my yy to x
return my yy's contents -- return duplicate elements
else
set t to my xx's item 1
set end of my yy to t
repeat with i from 2 to count my xx
set x to my xx's item i
if eq(x, t) then
else
set end of my yy to x
set t to x
end if
end repeat
return my yy's contents -- return uinque elements
end if
end script
tell o to run
end uniq
--END OF SCRIPT2
In order to apply it to your current Address Book problem, replace the main() handler with something like the following one.
--SCRIPT2a (part)
on main()
script o
-- input data
property xx : {} -- list of parent; given later
property yy : {} -- list of children per parent; given later
-- work list
property pp : {} -- list of children tagged by parent; i.e, lits of {child, parent}
property qq : {}
property rr : {}
-- (0) get input data from AB
tell application "Address Book"
tell people
set xx to its id
set yy to its every email's value
end tell
end tell
-- (1) build list of children tagged by parent *)
(* omitted (same as the previous) *)
-- (2) sort tagged list by child as key
(* omitted (same as the previous) *)
-- (3) retrieve parents with duplicate child
(* omitted (same as the previous) *)
-- (4) group the retrieved people in AB
tell application "Address Book"
repeat with r in my rr
add person id r to group "duplicate email"
end repeat
end tell
end script
tell o to run
end main
--END OF SCRIPT2a
Good luck,
Hiroto
Message was edited by: Hiroto -
Move a mouse with Apple script
Hello,
I need some apple script code to move a mouse to a certain location and then click. If possible could it record the location of the mouse, move it to the pre-assigned coordinates, click, and them move it back to where it was.
I am doing this so I can use multivid and Qlab to play different videos on different iOS devices. Multivid doesn't seem to let me have a cue list with different videos playing simultaneously.
I will have my iMac set up with 2 displays, one with Qlab and the other with multivid in full screen.
Thanks for the helpHere's another code using rubycocoa you might try.
_rb_click({|:position|:{30, 10}, |:click|:1, |:restore|:true, |:prep|:false})
on _rb_click(desc)
record desc : event descriptor record;
full spec = {|:position|:pos, |:click|:k, |:button|:b, |:flags|:m, |:restore|:r, |:prep|:p}
defaults = {|:position|:{}, |:click|:0, |:button|:1, |:flags|:"", |:restore|:false, |:prep|:true}
list pos : {x, y} or {}
number x, y = x, y global coordinate of position
{} denotes current location
integer k : click count (0, 1, 2 or 3}; 0 denotes only to move mouse and exit
integer b : button index (1 = left button, 2 = right button)
string m : modifier flags; e.g. 'ck' = control + command
a = capslock
s = shift
c = control
o = option
k = command
boolean r : true to restore original mouse location, false otherwise
boolean p : true to post preparatory left 1-click event to change UI context, false otherwise
return list : {x, y} = mouse location at exit
considering numeric strings
if (system info)'s system version < "10.9" then
set ruby to "/usr/bin/ruby"
else
set ruby to "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby"
end if
end considering
set defaults to {|:position|:{}, |:click|:0, |:button|:1, |:flags|:"", |:restore|:false, |:prep|:true}
set {|:position|:pos, |:click|:k, |:button|:b, |:flags|:m, |:restore|:r, |:prep|:p} to desc & defaults
if pos = {} then
set {x, y} to {"%", "%"}
else
set {x, y} to pos
end if
if k is not in {0, 1, 2, 3} then error "invalid click count: " & k number 8000
if b is not in {1, 2} then error "invalid button index: " & b number 8000
if m = "" then set m to "%"
do shell script ruby & " <<'EOF' - " & x & " " & y & " " & k & " " & b & " " & m & " " & r & " " & p & "
require 'osx/cocoa'
include OSX
if ARGV[0..1] == ['%', '%']
pt = CGEventGetLocation(CGEventCreate(nil)) # current mouse location
else
pt = CGPoint.new
pt.x, pt.y = ARGV[0..1].map {|a| a.to_f}
end
clk, btn = ARGV[2..3].map {|a| a.to_i}
flg = ARGV[4]
res, prep = ARGV[5..6].map {|a| a == 'true'}
etype, mbtn = case btn
when 1 then [KCGEventLeftMouseDown, KCGMouseButtonLeft] # [1, 0]
when 2 then [KCGEventRightMouseDown, KCGMouseButtonRight] # [3, 1]
when 3 then [KCGEventOtherMouseDown, KCGMouseButtonCenter] # [25, 2]
else raise ArgumentError, %[invalid mouse button: #{btn}]
end
mtable = {
'a' => KCGEventFlagMaskAlphaShift,
's' => KCGEventFlagMaskShift,
'c' => KCGEventFlagMaskControl,
'o' => KCGEventFlagMaskAlternate,
'k' => KCGEventFlagMaskCommand,
mf = flg.split(//).inject(0) { |mf, x| (m = mtable[x]) ? mf | m : mf }
src = CGEventSourceCreate(KCGEventSourceStateHIDSystemState)
tap = KCGHIDEventTap
pt0 = CGEventGetLocation(CGEventCreate(src)) # current mouse location
# move mouse to target location
ev0 = CGEventCreateMouseEvent(src, KCGEventMouseMoved, pt, 0) # move mouse
CGEventPost(tap, ev0)
if clk == 0
puts pt.x, pt.y
exit
end
# post preparatory left mouse click to change UI context (optional)
if prep
ev1 = CGEventCreateMouseEvent(src, KCGEventLeftMouseDown, pt, KCGMouseButtonLeft) # mouse left button down
CGEventPost(tap, ev1)
CGEventSetType(ev1, KCGEventLeftMouseUp) # mouse left button up
CGEventPost(tap, ev1)
end
# post target mouse click(s) with given flags
ev = CGEventCreateMouseEvent(src, etype, pt, mbtn) # mouse button down
CGEventSetFlags(ev, mf) # set flags
CGEventSetIntegerValueField(ev, KCGMouseEventClickState, clk) # set click count
CGEventPost(tap, ev)
CGEventSetType(ev, etype + 1) # mouse button up
CGEventPost(tap, ev)
# restore mouse location (optional)
if res
CGEventSetLocation(ev0, pt0) # restore mouse location
CGEventPost(tap, ev0)
puts pt0.x, pt0.y
exit
end
puts pt.x, pt.y
EOF"
set rr to paragraphs of result
repeat with r in rr
set r's contents to r as number
end repeat
return rr
end _rb_click -
Hello guys, I have an big Problem with my Programm in Apple script...
Everything of it works until a simple "duplicate" command. Then I will get error 10006 here is the script:
ps: I use "x" for folder name where I get "minecraft.jar"
tell application "Finder"
--Ermitteln des Ordner "Versionen" welcher sich im Ordner "Resources befindet"--
set i to (path to me) as string
set ii to (container of item i) as text
set theFolder to (container of folder ii) as text
set Versionen to folder "Versionen" of folder "Resources" of folder "Contents" of file i
--Application Support definieren--
set AppSupp to (path to application support from user domain) as text
--Einleitende Worte für das Programm--
display dialog "Willkommen im automatischen Versionen-Wechsel Programm für Minecraft. Bitte wählen Sie aus der folgenden Liste die Version, wechle Sie installiert haben wollen. -Ich weise darauf hin, dass die benützung auf eigene Gefahr ist."
--Auswahl der Version--
set liste to choose from list {"Vollversion 1.2.5", "Vollversion 1.2.3", "Vollversion 1.1", "Vollversion 1.0.0", "Beta 1.9 Pre 6", "Beta 1.8.1", "Beta 1.8", "Beta 1.7.3", "Beta 1.6.6", "Beta 1.5_01", "Beta 1.4_01", "Beta 1.3_01", "Beta 1.2_02", "Beta 1.1_02", "Beta 1.0"}
if liste is {"Vollversion 1.2.5"} then set x to "v_1.2.5"
if liste is {"Vollversion 1.2.3"} then set x to "v_1.2.3"
if liste is {"Vollversion 1.1"} then set x to "v_1.1"
if liste is {"Vollversion 1.0.0"} then set x to "v_1.0.0"
if liste is {"Beta 1.9 Pre 6"} then set x to "b_1.9 Pre 6"
if liste is {"Beta 1.8.1"} then set x to "b_1.8.1"
if liste is {"Beta 1.8"} then set x to "b_1.8"
if liste is {"Beta 1.7.3"} then set x to "b_1.7.3"
if liste is {"Beta 1.6.6"} then set x to "b_1.6.6"
if liste is {"Beta 1.5_01"} then set x to "b_1.5_01"
if liste is {"Beta 1.4_01"} then set x to "b_1.4_01"
if liste is {"Beta 1.3_01"} then set x to "b_1.3_01"
if liste is {"Beta 1.2_02"} then set x to "b_1.2_02"
if liste is {"Beta 1.1_02"} then set x to "b_1.1_02"
if liste is {"Beta 1.0"} then set x to "b_1.0"
--Ist Minecraft schon Installiert? Wenn Ja dann löschen--
if folder "minecraft" of folder AppSupp exists then
delete folder "minecraft" of folder AppSupp
end if
--MinecraftVorlage entpacken--
open file "minecraft.zip" of Versionen
--Pause--
delay 1
--Finder Fenster schließen--
close Finder window 1
--Vorbereiten der MinecraftVorlage--
duplicate file "mincraft.jar" of folder x of Versionen to folder "bin" of folder "minecraft" of Versionen.
Could anyone say me what's wrong with this line?
--Installieren--
duplicate folder "minecraft" of Versionen to AppSupp
--Pause--
delay 1
--Temporäre Dateien löschen--
delete folder "minecraft" of Verionen
--Alles Richtig?--
if folder "minecraft" of folder AppSupp exists then
display dialog "Die Installation von Minecraft wurde erfolgreich abgeschlossen!" with title "MC-Installer"
else
display dialog "Es ist leider ein unerwartetes Problem bei der Installation vorgelaufen." with title "MC-Installer"
end if
end tell
Error msg:
tell current application
path to current application
--> alias "Macintosh HD:Users:manuelfederanko:Desktop:VersioChanger.app:"
end tell
tell application "Finder"
get container of item "Macintosh HD:Users:manuelfederanko:Desktop:VersioChanger.app:"
--> "Macintosh HD:Users:manuelfederanko:Desktop:"
get container of folder "Macintosh HD:Users:manuelfederanko:Desktop:"
--> "Macintosh HD:Users:manuelfederanko:"
get folder "Versionen" of folder "Resources" of folder "Contents" of file "Macintosh HD:Users:manuelfederanko:Desktop:VersioChanger.app:"
--> folder "Versionen" of folder "Resources" of folder "Contents" of application file "VersioChanger.app" of folder "Desktop" of folder "manuelfederanko" of folder "Users" of startup disk
path to application support from user domain
--> alias "Macintosh HD:Users:manuelfederanko:Library:Application Support:"
display dialog "Willkommen im automatischen Versionen-Wechsel Programm für Minecraft. Bitte wählen Sie aus der folgenden Liste die Version, wechle Sie installiert haben wollen. -Ich weise darauf hin, dass die benützung auf eigene Gefahr ist."
--> {button returned:"OK"}
choose from list {"Vollversion 1.2.5", "Vollversion 1.2.3", "Vollversion 1.1", "Vollversion 1.0.0", "Beta 1.9 Pre 6", "Beta 1.8.1", "Beta 1.8", "Beta 1.7.3", "Beta 1.6.6", "Beta 1.5_01", "Beta 1.4_01", "Beta 1.3_01", "Beta 1.2_02", "Beta 1.1_02", "Beta 1.0"}
--> {"Beta 1.8.1"}
exists folder "minecraft" of folder "Macintosh HD:Users:manuelfederanko:Library:Application Support:"
--> false
open file "minecraft.zip" of folder "Versionen" of folder "Resources" of folder "Contents" of application file "VersioChanger.app" of folder "Desktop" of folder "manuelfederanko" of folder "Users" of startup disk
close Finder window 1
--> {}
copy file "mincraft.jar" of folder "b_1.8.1" of folder "Versionen" of folder "Resources" of folder "Contents" of application file "VersioChanger.app" of folder "Desktop" of folder "manuelfederanko" of folder "Users" of startup disk to folder "bin" of folder "minecraft" of folder "Versionen" of folder "Resources" of folder "Contents" of application file "VersioChanger.app" of folder "Desktop" of folder "manuelfederanko" of folder "Users" of startup disk
--> error number -1728 from file "mincraft.jar" of folder "b_1.8.1" of folder "Versionen" of folder "Resources" of folder "Contents" of application file "VersioChanger.app" of folder "Desktop" of folder "manuelfederanko" of folder "Users" of startup disk
Ergebnis:
error "„Finder“ hat einen Fehler erhalten: „folder \"bin\" of folder \"minecraft\" of folder \"Versionen\" of folder \"Resources\" of folder \"Contents\" of application file \"VersioChanger.app\" of folder \"Desktop\" of folder \"manuelfederanko\" of folder \"Users\" of startup disk“ kann nicht als „file \"mincraft.jar\" of folder \"b_1.8.1\" of folder \"Versionen\" of folder \"Resources\" of folder \"Contents\" of application file \"VersioChanger.app\" of folder \"Desktop\" of folder \"manuelfederanko\" of folder \"Users\" of startup disk“ gesetzt werden." number -10006 from folder "bin" of folder "minecraft" of folder "Versionen" of folder "Resources" of folder "Contents" of application file "VersioChanger.app" of folder "Desktop" of folder "manuelfederanko" of folder "Users" of startup diskpath to resource is straightforward. the command:
path to resource "filename.xxx"
will return an alias to /path/to/your app/Contents/Resources/filename.xxx, automatically accounting for placement of the app file in the file system. use the in directory parameter if you want to specify a subfolder of the resources folder. The only tricky thing about it is that when you run the script from the script editor it may think the currently running app is the script editor, not your app, and swo return a path to script editor's resource folder. -
I try downloading games and things but every time i do apple script comes up with an encrypted file. It has done this sense i bought this lap top. Please help me.
Okay, can you reply letting me know if the computer was purchased used?, this will help as it would identify the possibility that the prior owner did indeed create some sort of block.
Next, what you are speaking about blocks in regards to downloading 'PDF software'...is it PDF 'software' or PDF files that are blocked?, it appears that maybe it's the PDF files which are blocked at which case it indeed my be programmed into the system.
Please answer these and we can further assist you in reaching an answer. As for this list you have provided, I would need more than simple bullets....if you can provide the location of these 'bullets' and file extension...that would get the ball rolling.
Thanks -
Hi, I wrote a simple "sudo" script for people who prefer to use su rather than sudo.
#!/bin/bash
while [ -n "$1" ]
do
command="${command} $1"
shift
done
su -c "$command"
Usage:
put it in /usr/sbin, then for example, do
sudo pacman -Sy
Password:
enter root password
Advantages:
for those who don't like sudo, this sudo script is convenient for one line commands
simple bash completion
Hope you find it usefulXilon wrote:Couldn't you just do:
alias sudo='su -c'
That would require you to manually put ' ' around your command, and miss bash completion.
mucknert wrote:Uh. sudo allows a much finer selection of rights. You can say what user or group is allowed to execute with its own password (or no password at all) instead of the root pw. That's a lot more than your script does and those are good reasons, too. Read up on sudo one day. You will be suprised.
Thanks for your suggestion, I just had a quick read through sudo and sudoers. This is some stuff I found:
The time stamp issue was never a big one, and you can configure the time or disable it. I find sudo -k useful too.
I thought sudo might add security risk if the user password was compromised, but you can configure sudo to ask for the root password. However, this would defeat the purpose for those who disable root.
I also have a questions: if you want to do access control, why would you prefer sudo over simple file permissions? Or is sudo primarily used as a finer access control scheme?
Again, thanks for your advice, I really appreciate it. Please point out anything wrong with my questions. The manual was pretty long, so I'm bound to miss something. -
KeyNotes and Apple script / scripting Bridge
Hi
Sorry I am a recently started development in Mac OS, so may be this question is very simple for you guys
actually I am looking to manage Keynote application automatically from Mac Server application, I know apple script is available for lot of functionalities available in keynote but i want that all these things happend without showing anything on GUI , like i want to do all the automation on background without effecting the running GUI of keynote
if anybody can have idea how to do it in Apple script or using ScriptingBridge, I will really appriciate your help and supportdepending on what you want to do, this may or may not be possible (most likely not). Applescript works by scripting other applications: some applications are set up do do background tasks, some applications are duplicated by osax or unix utilities that operate invisibly, but most often applescript has to open a document in the application and work on it through the application.
scripting bridge is for cocoa developers: it allows cocoa apps to script other apps. it's not really useful for you unless you want to develop specialized software.
more details would be helpful.
Maybe you are looking for
-
Is there a 3rd Party Solution for Adobe's lack of recover for unsaved work?
Time and time again I am baffled by Adobe's inability or refusal to make the user experience consistent across it's entire Creative Suite. I am repeatedly shocked by the punitive error messages I receive in Photoshop. It's as though you don't really
-
CALL TRANSACTION VK13 AND SKIP FIRST SCREEN
Hi, I'm using ALV report and i want to call the the Tcode VK13 from alv and skip the screens. I have declared form user_command and calling from the "REUSE_ALV_LIST_DISPLAY". The actual issue is how to select the radio button in the pop up window and
-
Why wont my new iphpne sync to my itunes?
Im trying to sync my apps to my new iphone and it wont do it?? not sure why?
-
Text messages from ipad have all of a sudden stiopped working- help!!
ANyone having issues with ipad not sending texts? Had a carrier update on iphone and now texts not working from ipad.
-
Hi, I'm new to this and got a quick question about the OBIEE 11g Samples - the 5 tables : samp_addresses_D, samp_customers_d, samp_products_d, samp_revenue_f, samp_time_day_D from the first exercise for the Administration Tool (downloaded @ http://ww