Re: AppleScript-Users Digest, Vol 7, Issue 51
Re: AppleScript-Users Digest, Vol 7, Issue 51
- Subject: Re: AppleScript-Users Digest, Vol 7, Issue 51
- From: email@hidden
- Date: Wed, 27 Jan 2010 15:49:47 -0600
Thanks Mark and Luther for the suggestions.
I didn't totally understand all of it but I was able to get it to work
in the following script using your instructions:
do
shell script "rm -rf /Applications/Utilities/'Keychain
Minder.app'" with administrator
privileges
do shell script
"rm -f /Library/LaunchDaemons/com.apple.bindad.plist" with administrator
privileges
do shell script
"rm -f /Library/LaunchDaemons/com.apple.migrateaduser.plist"
with administrator
privileges
do shell script
"rm -f /System/Library/'User Template'/English.lproj/Library/Preferences/loginwindow.plist"
with administrator
privileges
do shell script
"rm -rf /Users/Shared/'AD Migration Assistant.app'" with administrator
privileges
do shell script
"rm -f /Users/Shared/prefs.plist" with administrator
privileges
_______________________________________________________________________________________________________
Jeffrey W. Madson |
Macintosh Systems Engineer | RR Donnelley Desktop Engineering
W6545 Quality Drive | Greenville, WI 54942
| (:
920-997-3768 |
Cell:
920-915-8619 |
*:
email@hidden
email@hidden
Sent by: applescript-users-bounces+jeffrey.madson=email@hidden
01/26/2010 10:53 AM
Please respond to
email@hidden |
|
To
| email@hidden
|
cc
|
|
Subject
| AppleScript-Users Digest, Vol 7, Issue
51 |
|
Send AppleScript-Users mailing list submissions to
email@hidden
To subscribe or unsubscribe via the World Wide Web, visit
http://lists.apple.com/mailman/listinfo/applescript-users
or, via email, send a message with subject or body 'help' to
email@hidden
You can reach the person managing the list at
email@hidden
When replying, please edit your Subject line so it is more specific
than "Re: Contents of AppleScript-Users digest..."
Today's Topics:
1. Re: If/Then Statements (Mark J. Reed)
2. Re: Determining Binary Type (Luther Fuller)
3. Applescript book recommendation (Cosgrave Valentine)
4. Re: If/Then Statements (Luther Fuller)
5. Re: Determining Binary Type (Marconi)
6. Re: Determining Binary Type (Luther Fuller)
7. Re: Applescript and referring to a folder (Mark J. Reed)
8. Subject: Fwd: [mac-dev-jobs] Need Mac Programmer for Text
extraction app (Mark Dawson)
----------------------------------------------------------------------
Message: 1
Date: Tue, 26 Jan 2010 10:37:21 -0500
From: "Mark J. Reed" <email@hidden>
Subject: Re: If/Then Statements
To: email@hidden
Cc: email@hidden
Message-ID:
<email@hidden>
Content-Type: text/plain; charset=UTF-8
The rm command signals an error if asked to remove something which
doesn't exist. If you want to ignore that error and move on, the
usual solution is to pass the -f flag to rm:
do shell script "rm -rf /path/to/some/folder" with administrator
privileges
or
do shell script "rm -f /path/to/some/file" with administrator
privileges
Alternatively, you can wrap the "do shell script" in a "try
... on
error" block so that it doesn't abort when the shell command signals
an error, but the problem there is that you might miss actual
meaningful errors as well: -f doesn't keep rm from failing if it has
no permission to remove the file, for instance.
Either way, if the list of files to delete isn't significantly larger
than what you sent, you could also do the whole thing as a single
shell command, which would be more efficient:
-- note no quotation marks inside these; we use 'quoted form of' later
set remove_these to { ¬
"/Applications/Utilities/Keychain Minder.app",
¬
"/Library/LaunchDaemons/com.apple.bindad.plist",
¬
"Library/LaunchDaemons/com.apple.migrateaduser.plist",
¬
"/System/Library/User
Template/English.lproj/Library/Preferences/loginwindow.plist", ¬
"/Users/Shared/AD Migration Assistant.app", ¬
"/Users/Shared/prefs.plist" }
set my_command to "rm -rf"
repeat with path_name in remove_these
set my_command to my_command & " " & quoted
form of path_name
end repeat
do shell script my_command with administrator privileges
You could also do them one at a time by putting the do shell script
inside the loop - less efficient but still easier to read than a big
long list of nearly identical statements in the source code.
On Tue, Jan 26, 2010 at 10:11 AM, <email@hidden>
wrote:
> I am essentially creating a uninstaller script. The script I have
works but
> if any element is already gone then it hangs at that point and gives
an
> error. I need to put in some kind of if/then statement I believe so
that
> when an error is returned it will move to the next line and so on
until
> finished. Any suggestions out there would be much appreciated.
>
> do shell script "rm -r /Applications/Utilities/'Keychain Minder.app'"
with
> administrator privileges
> do shell script "rm /Library/LaunchDaemons/com.apple.bindad.plist"
with
> administrator privileges
> do shell script "rm /Library/LaunchDaemons/com.apple.migrateaduser.plist"
> with administrator privileges
> do shell script "rm /System/Library/'User
> Template'/English.lproj/Library/Preferences/loginwindow.plist"
with
> administrator privileges
> do shell script "rm -r /Users/Shared/'AD Migration Assistant.app'"
with
> administrator privileges
> do shell script "rm /Users/Shared/prefs.plist" with administrator
privileges
>
> ____________________________________________________________________________________________________________________________________
> Jeffrey W. Madson | Macintosh Systems Engineer | RR Donnelley Desktop
> Engineering
> W6545 Quality Drive | Greenville, WI 54942 | Office: 920-997-3768
| Cell:
> 920-915-8619 | Email: email@hidden
>
>
> Â _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list    (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
>
--
Mark J. Reed <email@hidden>
------------------------------
Message: 2
Date: Tue, 26 Jan 2010 09:51:13 -0600
From: Luther Fuller <email@hidden>
Subject: Re: Determining Binary Type
To: Applescript Users <email@hidden>
Message-ID: <email@hidden>
Content-Type: text/plain; charset="us-ascii"
On Jan 26, 2010, at 9:32 AM, Marconi wrote:
> Given a path like: "/volumes/SomeVol/System/Library/CoreServices/Finder.app/Contents/
Mac OS/Finder" how do I find out whether the file 'Finder' is PPC,
Intel or Universal?
Use this ...
tell application "Finder" to kind of aliasToAppl
It returns the text "Application (Universal)" or "Application
(Intel)".
(Or "Application (PPC)", I suppose, haven't tested this.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.apple.com/mailman/private/applescript-users/attachments/20100126/3b862a4d/attachment.html
------------------------------
Message: 3
Date: Tue, 26 Jan 2010 15:56:20 +0000
From: Cosgrave Valentine <email@hidden>
Subject: Applescript book recommendation
To: email@hidden
Message-ID: <email@hidden>
Content-Type: text/plain; charset=us-ascii
Try AppleScript 1-2-3 by Sal Soghoian and Bill Cheeseman
------------------------------
Message: 4
Date: Tue, 26 Jan 2010 10:04:07 -0600
From: Luther Fuller <email@hidden>
Subject: Re: If/Then Statements
To: Applescript Users <email@hidden>
Message-ID: <email@hidden>
Content-Type: text/plain; charset="us-ascii"
On Jan 26, 2010, at 9:11 AM, email@hidden wrote:
> I am essentially creating a uninstaller script. The script I have
works but if any element is already gone then it hangs at that point and
gives an error. I need to put in some kind of if/then statement I believe
so that when an error is returned it will move to the next line and so
on until finished. Any suggestions out there would be much appreciated.
>
> do shell script "rm -r /Applications/Utilities/'Keychain Minder.app'"
with administrator privileges
I do that too. There are two ways to do it.
First ...
tell application "Finder"
if (exists file "fileName" of locationAlias) then
(file
"fileName" of locationAlias) as alias
tell
application "System Events" to delete disk item (the result as
text)
end if
end tell
Or you can use this ...
tell application "Finder"
try
((locationAlias
as text) & "fileName") as alias
tell
application "System Events" to delete disk item (the result as
text)
end try
end tell
If the file does not exist, then creating the alias from a text path fails.
Using "System Events" avoids putting anything in the Trash.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.apple.com/mailman/private/applescript-users/attachments/20100126/67edd734/attachment.html
------------------------------
Message: 5
Date: Tue, 26 Jan 2010 09:11:06 -0700
From: Marconi <email@hidden>
Subject: Re: Determining Binary Type
To: Applescript Users <email@hidden>
Message-ID: <p06240801c784c3705f59@[10.0.1.225]>
Content-Type: text/plain; charset="us-ascii"
At 9:51 AM -0600 1/26/10, Luther Fuller sent email regarding Re:
Determining Binary Type:
>On Jan 26, 2010, at 9:32 AM, Marconi wrote:
>
>>Given a path like:
>>"/volumes/SomeVol/System/Library/CoreServices/Finder.app/Contents/
>>Mac OS/Finder" how do I find out whether the file 'Finder'
is PPC,
>>Intel or Universal?
>>
>
>Use this ...
>
>tell application "Finder" to kind of aliasToAppl
I get an error:
tell application "Finder" to kind of
"/volumes/Bart/System/Library/CoreServices/Finder.app/Contents/ Mac
OS/Finder"
Can't get kind of
"/volumes/Bart/System/Library/CoreServices/Finder.app/Contents/ Mac
OS/Finder".
And I don't understand the syntax; is 'kind' a verb? If I want to set
a var, like 'bin_type' to the kind returned by Finder for the file
/volumes/Bart/System/Library/CoreServices/Finder.app/Contents/ Mac
OS/Finder" how do I do that?
set bin_type to ...?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.apple.com/mailman/private/applescript-users/attachments/20100126/31d0c002/attachment.html
------------------------------
Message: 6
Date: Tue, 26 Jan 2010 10:26:25 -0600
From: Luther Fuller <email@hidden>
Subject: Re: Determining Binary Type
To: Applescript Users <email@hidden>
Message-ID: <email@hidden>
Content-Type: text/plain; charset="us-ascii"
On Jan 26, 2010, at 10:11 AM, Marconi wrote:
> At 9:51 AM -0600 1/26/10, Luther Fuller sent email regarding Re: Determining
Binary Type:
>> On Jan 26, 2010, at 9:32 AM, Marconi wrote:
>>> Given a path like: "/volumes/SomeVol/System/Library/CoreServices/Finder.app/Contents/
Mac OS/Finder" how do I find out whether the file 'Finder' is PPC,
Intel or Universal?
>>
>> Use this ...
>>
>> tell application "Finder" to kind of aliasToAppl
>
> I get an error:
>
> tell application "Finder" to kind of "/volumes/Bart/System/Library/CoreServices/Finder.app/Contents/
Mac OS/Finder"
>
> Can't get kind of "/volumes/Bart/System/Library/CoreServices/Finder.app/Contents/
Mac OS/Finder".
In my example, 'aliasToAppl' must be an alias, not a posix path.
You need to change the posix path to an alias, then it will work.
For example ...
tell application "Finder" to kind of posix file "/volumes/..."
You can also use ...
alias "OS_X:System:Library:CoreServices:Finder.app:Contents:MacOS:Finder"
tell application "Finder" to kind of the result --> "Unix
Executable File (Intel)"
But why dig that deep into the Finder.app package?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.apple.com/mailman/private/applescript-users/attachments/20100126/9a217eaa/attachment.html
------------------------------
Message: 7
Date: Tue, 26 Jan 2010 11:32:31 -0500
From: "Mark J. Reed" <email@hidden>
Subject: Re: Applescript and referring to a folder
To: Rowland McDonnell <email@hidden>
Cc: email@hidden
Message-ID:
<email@hidden>
Content-Type: text/plain; charset="utf-8"
OK, analogies usually help; sorry for the confusion. My point is,
a
document object is not a file object. It may *refer* to a file, but
that
doesn't make it the same thing *as* a file.
Application objects, as far as AppleScript is concerned, are inviolable.
You
can't do anything with them except hand them back to the application you
got
them from and ask that application to do something on your behalf.
Less
figuratively, the only commands that you can apply to them are commands
defined by the application itself, not commands defined by some other
application. So you can't make a disk alias (which is a Finder command)
out
of a TeXShop document object, because the Finder doesn't know anything
about
TeXShop documents and TeXShop doesn't know how to make disk aliases.
What you can do is extract meaningful data out of application objects in
some universal form that can be used by other applications and by
AppleScript code that doesn't target any application: text strings are
a
good example. So a way to get an alias to a TeXShop document is to
do
exactly what you're doing - get the pathname, which, as a string, is
universal, and use that to construct the file reference needed by the Finder
to make an alias.
File objects and AppleScript "aliases" (not the Finder/disk kind)
are also a
universal type, and there may be a way to get one of those out of the
document object without having to go by way of the POSIX pathname. See
below.
> What Applescript refuses to do is to permit me to manipulate the file
to
> which that path refers, unless I go via a very ugly construction to
coerce
> the path data into something that Applescript understands as a file
pointer.
Having to say (POSIX file pathNameGoesHere) is not "a very ugly
construction" (or "nasty horrible ugly code") by AppleScript
standards; it
is the standard way to get a usable AppleScript object out of a POSIX path
name.
However, if you really need the "as string" at the end of "path
of
this_document", then you should look in the TeXShop dictionary (File->Open
Dictionary from Script Editor), in the document class, to see what the
type
of "path" actually is. You might be doing an unnecessary
double conversion
from a file reference to a string and back to a file reference - despite
the
name, the "path" might actually be an alias (in the AppleScript
sense)
instead of a string. If it is, then you might be able to use it
directly
(as long as you don't coerce it to a string first). e.g.
tell application "Finder" to make new alias at selected folder
to (path of
this_document)
> What do you mean by that? The document objects concerned all
have a file
> system path associated with them, which means to me that it's certainly
> formally connected to a file on disc.
It's incidentally connected to a file on disc. A document references
a file
on disc, but is not identical with a file on disc. This is an important
distinction. The file exists when the app is not open. The
document
doesn't. The document exists when created via File->New, before
being
saved, even though it has no file on disc associated with it.
Trying to access a TeXShop document will launch TeXShop if it's not running.
Renaming, making an alias to, deleting, or otherwise manipulating the file
on disc that holds the document will not involve TeXShop at all.
They're different objects. They have an association between them,
but
they're not interchangeable.
>> AppleScript will happily coerce a path into a file,
>
> It has failed to do so when I've asked it to.
It depends on how you ask, and what kind of path you have. If you
have a
POSIX path, you have to use the POSIX file constructor syntax, (POSIX file
pathNameGoesHere). But if you have a Mac-style path, then just
(pathNameGoesHere as alias) will work; that is a coercion. You can
also
use the non-POSIX file constructor syntax (file pathNameGoesHere) with
a Mac
path.
>> As an unrelated point, nested tell blocks are just begging for
>> terminology conflicts.
>
> I don't understand what that means.
You have a 'tell application "Finder"' block inside a 'tell application
"TeXShop"' block. As a general rule, nesting tell blocks
like that is
inadvisable, because a tell block imports the application's terminology
into
the current namespace, and you could wind up with terminology conflicts.
The compiler is not really confused, of course. But you will get
confusing
results. Worse, you will not necessarily get any warning from the
compiler
that there is a conflict.
>> So I wouldn't
>> put a "tell Finder" block inside a "tell TeXShop"
block; get all the
>> pathnames out of TeXshop first and then make the aliases separately.
>
> I don't understand you.
Right now you're doing the alias-making inside the "tell TeXShop"
block.
It's interleaved:
1. get a document from TeXShop
2. tell Finder to make an alias
3. go back to 1 while there are any more documents
Every time through the loop, you're talking to both applications, and since
the TeXShop tell block encompasses the whole loop, the Finder loop
is
inside it. It's not really a problem in this particular case; it's just
not
best practice.
Instead, you can split it into two phases:
1. Query TeXShop for the pathnames of all its open documents.
2. Tell Finder to make aliases to all the corresponding files.
> Okay - could you perhaps explain the meaning and function of this
line,
> which uses coding I'm not familiar with:
>
> set all_paths to (get the path of every document)
It constructs a list containing the paths of all the documents.
The "every document" by itself is the same as "documents"
- it returns a
list of all the document objects.
Applying "(the) path of" to "every document" causes
it to apply "path of" to
each document in the list and return the list of results. So instead
of a
list of document objects, you have a list of paths. (The word "the"
is a
no-op intended to make the code read better as English.)
The "get" makes sure that you have an actual copy of the path
data on the
AppleScript side, rather than just a reference to data that you have to
talk
to TeXShop to manipulate.
The following loop achieves the same result more verbosely:
set all_paths to {} -- empty list
tell application "TeXShop"
repeat with a_document in documents
set end of all_paths to (get the path of a_document)
end repeat
end tell
The end result is a list, where each item of the list is the result of
asking TeXShop for the path of one of its documents.
I was assuming that "path" returned a string, by the way, which
may not be
the case, as discussed above. You can add "as string" to
the end of the
"get the path of every document" command if needed, or if it
turns out that
"path" returns an alias or file object in the first place, just
get rid of
the "POSIX file" in the "make new alias" command.
--
Mark J. Reed <email@hidden>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.apple.com/mailman/private/applescript-users/attachments/20100126/10e83482/attachment.html
------------------------------
Message: 8
Date: Tue, 26 Jan 2010 08:51:53 -0800
From: Mark Dawson <email@hidden>
Subject: Subject: Fwd: [mac-dev-jobs] Need Mac Programmer for Text
extraction app
To: email@hidden
Message-ID: <email@hidden>
Content-Type: text/plain; charset="iso-8859-1"
I saw this posting and thought it was appropriate for this list -- I think
this could be done in AppleScript (maybe with a helper app?). If
so, I thought I"d pass it along to all of you (I'm not in a position
to research or bid on this job)…
Mark
Begin forwarded message:
> From: whizbangresearch <email@hidden>
> Date: January 25, 2010 9:47:22 AM PST
> To: email@hidden
> Subject: [mac-dev-jobs] Need Mac Programmer for Text extraction app
>
> I am a researcher with little knowledge of programming and need help.
>
> Here is what I am looking for; don't know if it's possible.
>
> In simple terms I am in need of a custom program that would extract
text from multiple PDF documents and paste it (reformatted) into an Apple
Pages document.
>
> In my research, I collect online articles and documents and use the
"Save As" command to save these articles as PDFs into a folder.
I then use a program called "Skim" to highlight sections of the
documents and manually cut and paste my highlights into a Pages document
for further editing.
>
> Ideally, I would like to be able to extract the text from multiple
documents and have them pasted into Pages in different sections.
>
> Don't know if this is feasible or what the cost would be. Would like
to know if this is a possibility.
>
> --Steve
>
> __,_._,___
-------------- next part --------------
Skipped content of type multipart/related
------------------------------
_______________________________________________
AppleScript-Users mailing list
email@hidden
http://lists.apple.com/mailman/listinfo/applescript-users
End of AppleScript-Users Digest, Vol 7, Issue 51
************************************************
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden