How do I remove a group from an xcode project using AppleScript - applescript

I've successfully managed to add files to a group with AppleScript, but I also need to be able to remove a child group.
I thought something like
tell currentGroup
--remove any groups already present
repeat with groupItem in groups
--display alert " " & name of groupItem
remove groupItem from groups
end repeat
end tell
but it tells me that remove is not supported by that container.
Any ideas?

Such can be accomplished by for example the following:
tell application "Xcode"
tell front project
set parent_group to first group
delete first group of parent_group
end tell
end tell

I figured it out. To remove all groups in a group I can just do
delete groups of currentGroup
I'm not sure how I would remove just a single group though.

Related

AppleScript change Outlook signature

I wrote an application for my colleagues so that they can easily set their Outlook signature. Here is the code:
property includeInRandom : false
property sigName : "${signature.name}"
property sigContent : "${signature.content}"
try
tell application "Microsoft Outlook"
activate
set newOutlookSignature to make new signature with properties ¬
{name:sigName, content:sigContent, include in random:includeInRandom}
end tell
end try
The problem is that if a colleague changes his signature in the application and sets it in Outlook again there are two signatures with the same name. Is it possible to check if the current signature already exists and if it exists it should be edited/updated?
I don't have Microsoft Outlook, so I can't test my suggestions out, but I imagine you could get every signature whose name is sigName, then decide if you want to just delete them all and make a new one, or keep one, edit it, and delete the rest. I'm obviously working on the assumption there could be anywhere between 0 and N signatures sharing one name that have accumulated over time. From this standpoint, I'd say that deleting them all and making new one would be easiest coding wise, provided Outlook lets you delete a list of signatures the way, say, Finder lets you delete a list of files in a single command:
tell application "Microsoft Outlook" to delete every signature whose name is sigName
If it doesn't, you would have to construct a repeat loop and delete them one by one:
tell application "Microsoft Outlook" to repeat with S in ¬
(every signature whose name is sigName)
set S to the contents of S # (dereferencing)
delete S
end repeat
If you decide you want to keep one and edit it, then:
tell application "Microsoft Outlook"
set S to every signature whose name is sigName
if (count S) is 0 then
# make new signature
else
set [R] to S
delete the rest of S
set the content of R to the sigContent
end if
end tell
If delete the rest of S doesn't work, a repeat loop again will let you delete items 2 onwards individually, and keep just the first item to edit.
I'm sorry I can't test this for you, but it's at least an indication of how to go about trying to do it.

Removing People from Contacts Group (in Mac Address Book)

This is my first post in stackoverflow. I've spent weeks trying to get an Applescript to remove people from established Groups (not Smart Groups) in Contacts (Mac Address Book). The script removes several people then issues an error. If I re-run the script after the error is issued, it will remove a few more people from the group and then issue the same error again. I can continue doing this until eventually everyone is removed from the group. I don't understand why the error is issued when re-running the script after the error is issued results in a few more people being removed before the error is issued again. - And again, I can continue re-running the script until eventually every person is removed from the group. This suggests the contact records are not corrupted.
I've tried moving the SAVE command around but that didn't help. The Group I'm removing contacts from is labeled "Family".
The error issued is...
error "Contacts got an error: Can’t get group \"Family\"." number -1728 from group "Family"
tell application "Contacts"
set group_list to name of every group
repeat with anItem in group_list
set AppleScript's text item delimiters to ""
repeat 1 times
if first item of anItem is not "$" then exit repeat
set AppleScript's text item delimiters to "$"
set gruppe to text item 2 of anItem
if group gruppe exists then
--remove every person from group
repeat with person_to_remove in every person in group gruppe
set firstName to first name of every person in group gruppe
set group_count to count every person in group gruppe
remove person_to_remove from group gruppe
save
end repeat
end if
end repeat
end repeat
save
return "Done"
end tell
I think you're trying to hard. There is no need to change applescripts text item delimiters you can still find out if the group has a $ a the beginning of the group name
creating a 1 time loop is just weird not sure why you chose to do it that way.
you know the group already exists because you are looping through them so no need for that either
so here it is
tell application "Contacts"
set group_list to name of every group
repeat with aGroup in group_list
if first item of aGroup is "$" then
set thePeople to every person in group aGroup
repeat with aPerson in thePeople
remove aPerson from group aGroup
end repeat
end if
end repeat
save
end tell

Having trouble with remote folder actions with AppleScript

So I have an Applescript to help with naming photo's appropriately for data entry to assign it to a Unique ID. Since we're using Mac's this is done in AppleScript. This works great but it's only for one machine. What is now needed is to work on multiple machines. What I want to do is put the photos on our server and have the client machines do the action on the folder from there.
The problem I am currently having is that the script does not authenticate the user and does not run the script even though the info is correct. Am I doing this correctly?
tell application "Finder" of machine "eppc://user:password#server.local"
set renameFiles to the selection
set inventoryFiles to every file in folder (((path to documents folder) as text) & "Inventory Photos")
set currentIndex to the count of inventoryFiles
repeat with i from 1 to the count of renameFiles
set currentFile to (item i of renameFiles)
set new_name to ((10000 + currentIndex + i) as text) & ".jpg"
set name of currentFile to "a" & new_name
end repeat
end tell
Thank you for any help

Get unrecognized file extension in applescript

I was wondering how to return just the file extension from a string. I've tried the 'set variable to name extension of...' detailed in this question, but that only seems to work for recognized extensions. The idea is to sort files with the extension '.meta' into their own collection.
What I have now looks like
tell application "Finder'
set everyName to name of every item in entire contents of this_folder
end tell
set metaFiles to {}
repeat with n from 1 to count of everyName
set currentName to item n of everyName
set currentExt to last word of currentName --this assignment fails
if currentExt is "meta" then
set end of metaFiles to currentExt
end if
end repeat
I'm brand new to applescript so I appreciate any and all help/direction. Thanks!
Edit: Hacky Solution
I solved this by using the split function described here to break up the filename after every period. I grabbed the last string, made sure it wasn't the same as the first string in case there were no period characters, and then stored the corresponding filename.
The name includes the file extension, whether the Finder recognizes it or not. So just sort on the name like this...
tell application "Finder"
set metaFiles to (every item in entire contents of this_folder whose name ends with "meta") as alias list
end tell
If you aren't getting a name extension, make sure there actually is one and that you aren't looking at the end of the name. If you are going to be moving files around, you will also need to get the path, and not just the name. I don't think that making a list of your extensions is what you are going for, either - several different characters are used for word boundaries, but a period isn't one of them.
Why not just ask Finder for your file items?
tell application "Finder"
set metaFiles to (every item in entire contents of this_folder whose name extension is "meta") as alias list
end tell

AppleScript Word Count Service

I am trying to create a service in OSX leopard that counts the number of words of selected text. I have automator set to run an applescript, with the following put in it:
on run {input, parameters}
count words of input
display alert "Words: " & input
return input
end run
When I compile the script, it says it cannot count every word. What am I doing wrong?
Thanks for the help,
Elliott
First of all, I presume you are testing this in Automator, and that's where the error is taking place? If so, the likely problem is that there is no input—so it can't count the words of nothing. In order to test it successfully, you need to temporarily add a "Get Specified Text" action before the Run AppleScript action, and enter some test text into that field. You'll have to remove the Get Specified Text action before using it as an actual service.
Secondly, you need to use
count words of (input as string)
in order to get a proper count, otherwise it'll return zero.
I made one here, on Github:
https://gist.github.com/1616556
The current source is:
on run {input, parameters}
tell application "System Events"
set _appname to name of first process whose frontmost is true
end tell
set word_count to count words of (input as string)
set character_count to count characters of (input as string)
tell application _appname
display alert "" & word_count & " words, " & character_count & " characters"
end tell
return input
end run
Use Automator.app to create a new service, and then select the Run AppleScript action. Paste this code in to the text box, and save as Word and Character Count. Now switch to a new app, select some text, and open the context menu to find the new option.

Resources