Prüfen ob eine Datei geöffnet ist oder nicht…

Finde ich praktisch, gerade bei Ordneraktionen...

set thefile to choose file

checkifopened(thefile, 60)

on checkifopened(this, mytimeout)

## this file reference

## timeout in seconds

set a to POSIX path of (this as alias)

set startdate to current date

repeat until 1 = 0

## don't like that one because it relies on an error msg ... so

(** try

set b to do shell script "lsof | grep " & quoted form of a

on error

exit repeat

end try**)

##so I use this one

set b to do shell script "lsof"

if b does not contain a then

return true

else if ((current date) - startdate) > mytimeout then

return false

else

##say "still opened"

end if

end repeat

end checkifopened

This entry was posted in Useful Snippets and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CAPTCHA:


6 × two =

Subscribe without commenting

  • Seite übersetzen:


    Paypal for Pizza:




  • Kategorien


  • Letzte Kommentare

    • Niklas: Vielen Vielen Dank! So klappt es!
    • hubi: Servus Niklas, ich habe mir den Quellcode noch einmal angesehen und habe nun unter 10.7.3 einen Weg gefunden...
    • Niklas: Klingt super das Script. Leider bekomm ich immer folgende Fehlermeldung: error “„Mail“ hat einen Fehler...
    • Jürgen: Hallo Hubi, beim Abfragen von Kennworten gibt es noch eine böse Falle: Das Format, in dem security antwortet,...
    • hubi: Am einfachsten Du öffnest im AppleScript-Editor mal das Funktionsverzeichnis (unter Ablage) von iTunes. Ein...