rbhutani

Q: Applescript to record webcam video

Hi,

 

I am new to applescripts and I am trying to write a script to record from webcam for say X seconds. I am using the script below but I am getting an error that I do not have permission to save this file to Desktop. How can I avoid this error? Secondly how can I save the file with Date and Time stamp appended in the name of the file.

 

Thanks a lot in advance, this is my first post in the community

 

tellapplication "QuickTime Player"
  set newMovieRecording to new movie recording

  tell newMovieRecording
  start
  delay 5
  pause
  save newMovieRecording in "/users/rohitbhutani/desktop/movie.mov"
  stop
  close newMovieRecording
  end tell

MacBook Air, OS X Mavericks (10.9.5)

Posted on Jul 15, 2016 7:22 AM

Close

Q: Applescript to record webcam video

  • All replies
  • Helpful answers

  • by Perfectionniste,Helpful

    Perfectionniste Perfectionniste Jul 15, 2016 8:41 AM in response to rbhutani
    Level 1 (14 points)
    Jul 15, 2016 8:41 AM in response to rbhutani

    Hi rbhutani,

     

    First of all, you should have written

               save newMovieRecording in POSIX file "/Users/rohitbhutani/Desktop/movie.mov"

    instead of

               save newMovieRecording in "/Users/rohitbhutani/Desktop/movie.mov"


    Next, in order to save the file with Date and Time stamp appended in the name of the file, you could proceed as follows:

     

    set theCurrentDate to current date

    set dateTime to short date string of theCurrentDate & space & time string of theCurrentDate

    set theFilePath to "/Users/rohitbhutani/Desktop/movie " & dateTime & ".mov"

     

    tell application "QuickTime Player"

         set newMovieRecording to new movie recording

         tell newMovieRecording

               start

               delay 5

               pause

               save newMovieRecording in POSIX file theFilePath

               stop

               close newMovieRecording

         end tell

    end tell

  • by rbhutani,

    rbhutani rbhutani Jul 15, 2016 8:42 AM in response to Perfectionniste
    Level 1 (4 points)
    Mac OS X
    Jul 15, 2016 8:42 AM in response to Perfectionniste

    Hi Perfectionniste,

     

    Thanks for the quick reply. I tried your script and got an error

    "The document “Movie Recording” could not be saved as “16 9/11/07 pm.mov”. The file doesn’t exist.

     

    Any idea why this could be happening?

    Thanks,
    Rohit

  • by Pierre L.,

    Pierre L. Pierre L. Jul 15, 2016 8:55 AM in response to rbhutani
    Level 5 (4,484 points)
    Jul 15, 2016 8:55 AM in response to rbhutani

    First, it was by mistake that I posted my previous message under a very old username of mine.

     

    I have tested the script with the French Canadian version of OS X where the datetime variable was in the form "16-07-15 11:49:49", without any slash.

     

    Does the script work if you temporarily set dateTime to any short text string? For example: set dateTime to "today"

  • by Pierre L.,Solvedanswer

    Pierre L. Pierre L. Jul 15, 2016 9:08 AM in response to rbhutani
    Level 5 (4,484 points)
    Jul 15, 2016 9:08 AM in response to rbhutani

    The following should do the trick:

     

    set theCurrentDate to current date

    set dateTime to short date string of theCurrentDate & space & time string of theCurrentDate

    set P to offset of "/" in dateTime

    set dateTime to text 1 through (P - 1) of dateTime & "-" & text (P + 1) through -1 of dateTime

    set P to offset of "/" in dateTime

    set dateTime to text 1 through (P - 1) of dateTime & "-" & text (P + 1) through -1 of dateTime

    set theFilePath to "/Users/rohitbhutani/Desktop/movie " & dateTime & ".mov"

     

    tell application "QuickTime Player"

         set newMovieRecording to new movie recording

         tell newMovieRecording

               start

               delay 5

               pause

               save newMovieRecording in POSIX file theFilePath

               stop

               close newMovieRecording

         end tell

    end tell

  • by rbhutani,

    rbhutani rbhutani Jul 15, 2016 9:13 AM in response to Pierre L.
    Level 1 (4 points)
    Mac OS X
    Jul 15, 2016 9:13 AM in response to Pierre L.

    Yes it runs perfectly when I changed it to "today". And then I just used theCurrentDate in the name and it worked fine as well. Thanks a lot Pierre ! It solves my issue.

     

    If you don't mind I just had one more question. How would I change the video source to an external cam if needed to in future?

     

    Regards,

    Rohit

  • by Pierre L.,

    Pierre L. Pierre L. Jul 15, 2016 9:16 AM in response to rbhutani
    Level 5 (4,484 points)
    Jul 15, 2016 9:16 AM in response to rbhutani

    rbhutani wrote:

     

    How would I change the video source to an external cam if needed to in future?

     

    That, I don't know. I've never used any other camera with my MacBook Pro. Sorry.

  • by rbhutani,

    rbhutani rbhutani Jul 15, 2016 9:17 AM in response to Pierre L.
    Level 1 (4 points)
    Mac OS X
    Jul 15, 2016 9:17 AM in response to Pierre L.

    No issues. Thanks a lot Pierre for resolving the issue so quickly. Bon Weekend !

  • by Pierre L.,

    Pierre L. Pierre L. Jul 15, 2016 10:49 AM in response to rbhutani
    Level 5 (4,484 points)
    Jul 15, 2016 10:49 AM in response to rbhutani

    It was my pleasure. Many thanks for your feedback.

  • by Pierre L.,Helpful

    Pierre L. Pierre L. Jul 16, 2016 11:18 AM in response to rbhutani
    Level 5 (4,484 points)
    Jul 16, 2016 11:18 AM in response to rbhutani

    rbhutani wrote:

     

    How would I change the video source to an external cam if needed to in future?

     

    I had completely forgotten this thread: Click a menu option - can't figure out hierarchy